Skip to content
Advertisement

How do I get the Swagger-generated Python client to work?

I have generated the python client and server from https://editor.swagger.io/ – and the server runs correctly with no editing, but I can’t seem to get the client to communicate with it – or with anything.

I suspect I’m doing something really silly but the examples I’ve found on the Internet either don’t work or appear to be expecting that I understand how to craft the object. Here’s my code (I’ve also tried sending nothing, a string, etc):

JavaScript

I’m using python 3.6.4 and when the above runs I get:

JavaScript

I feel I’m making an incredibly basic mistake, but I’ve literally copied the JSON from https://editor.swagger.io/ – but since I can’t find an actually working example I don’t know what I’m missing.

Advertisement

Answer

The Python client generator produces object-oriented wrappers for the API. You cannot post a dict or a JSON string directly, you need to create a Pet object using the generated wrapper:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement