in Python, I want to do rest requests with HTTP and NOT with HTTPS, packages don't seem to agree

守給你的承諾、 提交于 2019-12-11 14:04:23

问题


I have tried to use request:

url = 'http://bot'    # this is a local service
import requests

r = requests.get(url)

and I get

requests.exceptions.SSLError: HTTPSConnectionPool(host='bot', port=443)

I specified HTTP, not HTTPS, but it tried to connect with SSL.

So, I tried httplib2:

url = 'http://bot'    # this is a local service
response, content = http.request(url, "GET")

and I get:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

I don't know why there is an obsession with HTTPS, but I don't want it. it's a local service running in development and it is pure HTTP. Adding ":80" to the url doesn't change anything.

When using CURL or C# to access the same service, through HTTP, no problem.

How can I tell python libs that I want a pure HTTP connection and nothing else?


回答1:


Use requests library and add a ssl verify option. Your request line should look like this:

r = requests.get(url, verify = False)



回答2:


Try to disable SSL_VERIFICATION

r = requests.get(url, verify = False)


来源:https://stackoverflow.com/questions/57111689/in-python-i-want-to-do-rest-requests-with-http-and-not-with-https-packages-don

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!