我已经从中生成了python客户端和服务器
https://editor.swagger.io/
-服务器运行正常,无需编辑,但我似乎无法让客户端与它通信,或者与任何东西通信。
我怀疑我在做一些非常愚蠢的事情,但我在互联网上找到的例子要么不起作用,要么似乎期望我了解如何制作对象。这是我的代码(我也尝试过不发送任何内容、字符串等):
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 that needs to be added to the store
try:
# Add a new pet to the store
api_instance.add_pet(body)
except ApiException as e:
print("Exception when calling PetApi->add_pet: %s\n" % e)
我正在使用python 3.6.4,当运行上述命令时,我得到:
Traceback (most recent call last):
File "petstore.py", line 14, in <module>
body = swagger_client.Pet(python_d) # Pet | Pet object that needs to be added to the store
File "/Users/bombcar/mef/petstore/python-client/swagger_client/models/pet.py", line 69, in __init__
self.name = name
File "/Users/bombcar/mef/petstore/python-client/swagger_client/models/pet.py", line 137, in name
raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501
ValueError: Invalid value for `name`, must not be `None`
我觉得我犯了一个难以置信的基本错误,但我实际上是从
https://editor.swagger.io/
-但由于我找不到一个实际可行的例子,我不知道我遗漏了什么。