swagger python自动化用例_如何让Swaggergenerated Python客户机正常工作?
我已經(jīng)從https://editor.swagger.io/生成了python客戶機和服務(wù)器,服務(wù)器沒有任何編輯就可以正常運行,但是我似乎無法讓客戶機與它或任何東西進行通信。在
我懷疑我在做一些非常愚蠢的事情,但是我在互聯(lián)網(wǎng)上找到的例子要么不起作用,要么似乎希望我能理解如何制作這個物體。以下是我的代碼(我也嘗試過不發(fā)送任何內(nèi)容、字符串等):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)
我使用的是python3.6.4,當上面運行時,我得到:
^{pr2}$
我覺得我犯了一個難以置信的基本錯誤,但是我確實從https://editor.swagger.io/復(fù)制了JSON-但是由于我找不到一個實際工作的示例,我不知道我遺漏了什么。在
總結(jié)
以上是生活随笔為你收集整理的swagger python自动化用例_如何让Swaggergenerated Python客户机正常工作?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 读png的值变了_pyth
- 下一篇: facebook对话链接_并非里程碑!