This article mainly introduces the relevant information on the collection of error reporting methods for Python requests. Friends who need it can refer to it
Both the python version and the ssl version will cause requests to be used when requesting https websites. There will be some errors, it is better to use the newer version.
1 Python2.6x use requests
An old application is running on an old Centos machine. After adding a new module, an error is reported. InsecurePlatformWarning: A true SSLContext object is not available.
/usr/lib/python2.6/site-packages/requests/packages/urllib3/util/ssl_.py:132: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarning
Solution
Use an old version of requests
$pip install requests==2.5.3
Or install it like this
$ pip install requests[security]
2 SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
The error is as follows version python2.7.5
Traceback (most recent call last):
File "./test.py", line 24, in <module>
response = requests.get(url1, headers=headers)
File "build/bdist.linux-x86_64/egg/requests/api.py ", line 52, in get
File "build/bdist.linux-x86_64/egg/requests/api.py", line 40, in request
File "build/bdist.linux-x86_64/egg/requests /sessions.py", line 209, in request
File "build/bdist.linux-x86_64/egg/requests/models.py", line 624, in send
File "build/bdist.linux-x86_64/egg/requests/models.py", line 300, in _build_response
File "build/bdist.linux-x86_64/egg/requests/models.py" , line 611, in send
requests.exceptions.SSLError: [Errno 1] _ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Solution
Verify can be disabled
>>> requests.get('https://google.com', verify=True)
Problem address python-requests-throwing-up-sslerror
3 SSLError: bad handshake
SSLError: bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],) python2.7.5
pip uninstall -y certifi && pip install certifi==2015.04.28
For discussion, see: https://github.com/rackspace/pyrax/issues/601
The above is given by the editor This is a collection of error reporting methods for Python requests introduced. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time!
The above is the detailed content of Summary of methods to solve Python requests error reporting. For more information, please follow other related articles on the PHP Chinese website!