小编bom*_*car的帖子

如何让 Swagger 生成的 Python 客户端运行?

我已经从https://editor.swagger.io/生成了 python 客户端和服务器- 并且服务器无需编辑即可正确运行,但我似乎无法让客户端与其通信 - 或与任何东西进行通信。

我怀疑我正在做一些非常愚蠢的事情,但我在互联网上找到的示例要么不起作用,要么似乎期望我了解如何制作该对象。这是我的代码(我也尝试过不发送任何内容、字符串等):

import time
import swagger_client
import json
from swagger_client.rest import ApiException
from pprint import pprint

# Configure OAuth2 access token for authorization: petstore_auth
swagger_client.configuration.access_token = 'special-key'
# create an instance of the API class
api_instance = swagger_client.PetApi()
d = '{"id": 0,"category": {"id": 0,"name": "string"},"name": "doggie","photoUrls": ["string"],  "tags": [ {      "id": 0,      "name": "string"    }  ],  "status": "available"}'
python_d = json.loads(d)
print( json.dumps(python_d, sort_keys=True, indent=4) )
body = swagger_client.Pet(python_d) # Pet | Pet object …
Run Code Online (Sandbox Code Playgroud)

python client json swagger

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

client ×1

json ×1

python ×1

swagger ×1