Swagger - Python 客户端 - 禁用 SSL 验证
Swagger - Python Client - Disable SSL verification
使用 Swagger 编辑器,我描述了我的 API 并下载了 Swagger Python 客户端(基于我的 API 描述)来测试我的 REST 服务(运行 在 HTTPS 上的 Wildfly 中)。
我在 Python 客户端附带的 configuration.py 中看到以下代码块:
self.verify_ssl = True
我已将此值设置为 false(出于测试目的),但我仍然继续收到:
调用 PApi 时出现异常->example_response_post: (0)
原因:SSL错误
[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:590)
使用以下测试客户端时:
# 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: %s\n" % e
事实上,我认为这个 configuration.py 文件从未加载过。我该如何着手进行这项工作?
提前致谢!
对我来说,一个临时的解决方法是使用 http 而不是 https,您可以在 configuration.py 中取消设置,只需为您的主机名写入 http://.... 而不是 https://。例如:
self.host = "http://localhost:8080"
最好的方法是通过将您发现的行更改为以下行来禁用 SSL 验证:
self.verify_ssl = False
但随后您需要重新运行由 swagger API:
自动生成的设置
python setup.py install --user
然后您的连接也应该适用于 https。但是请注意,您不会受到中间人攻击。
使用 Swagger 编辑器,我描述了我的 API 并下载了 Swagger Python 客户端(基于我的 API 描述)来测试我的 REST 服务(运行 在 HTTPS 上的 Wildfly 中)。
我在 Python 客户端附带的 configuration.py 中看到以下代码块:
self.verify_ssl = True
我已将此值设置为 false(出于测试目的),但我仍然继续收到:
调用 PApi 时出现异常->example_response_post: (0) 原因:SSL错误 [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:590)
使用以下测试客户端时:
# 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: %s\n" % e
事实上,我认为这个 configuration.py 文件从未加载过。我该如何着手进行这项工作?
提前致谢!
对我来说,一个临时的解决方法是使用 http 而不是 https,您可以在 configuration.py 中取消设置,只需为您的主机名写入 http://.... 而不是 https://。例如: self.host = "http://localhost:8080"
最好的方法是通过将您发现的行更改为以下行来禁用 SSL 验证:
self.verify_ssl = False
但随后您需要重新运行由 swagger API:
自动生成的设置python setup.py install --user
然后您的连接也应该适用于 https。但是请注意,您不会受到中间人攻击。