Swagger – Python Client – Disable SSL verification

Question:

Using Swagger Editor, I have described my API and have downloaded the Swagger Python client (based on my API description) to test against my REST service (running in Wildfly on HTTPS).

I see in the configuration.py that comes with the Python client there is the following code block:

self.verify_ssl = True

I have set this value to false (for testing purposes), but I still continue to receive:

Exception when calling PApi->example_response_post: (0)
Reason: SSLError
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

When using the following test client:

# create an instance of the API class
api_instance = swagger_client.PApi()
body = swagger_client.exampleRequestBody("some stuff") 
http_client_timeout = 5.4 # float | Set the value of the http request timeout (optional)

try:
    # Product Types
    api_response = api_instance.example_response_post(body=body)
    pprint(api_response)
except ApiException as e:
    print "Exception when calling PApi->example_response_post: %sn" % e

In fact, I dont think this configuration.py file is ever loaded. How can I go about making this work?

Thanks in advance!

Asked By: Bryce

||

Answers:

For me a temporary workaround is to use http instead of https, you can unset it in the configuration.py just write http://…. instead of https:// for your hostname. For example:
self.host = “http://localhost:8080

Answered By: intereested

The best way is to disable SSL verification by changing the line you spotted into:

self.verify_ssl = False

but then you need to rerun the setup that was autogenerated by the swagger API:

python setup.py install --user

and then your connection should work with http:// as well. Note that however you are not covered against Man-in-the-middle attacks.

Answered By: cordic
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.