Reputation: 9046
Python's Requests library bundles the chardet
and urllib3
packages.
This can mean that the bundled version will have bugs. I am wondering if there is a clean or easy way to get Requests to use a different version of urllib3. For example, could I pip install requests urllib3
and then have requests use that version automatically?
I know that Requests automatically uses certifi
instead of its bundled certificate, if certifi
is installed, but I couldn't find documentation like this for urllib3
.
Otherwise the options I see are:
Upvotes: 2
Views: 1810
Reputation: 18157
The options you've outlined are correct as of today.
There has been some talk of having a Requests setting which uses the system version of urllib3, but I don't believe it has been implemented. Some Linux distributions' packaging actually patches Requests to use the system version of urllib3 (and pin it accordingly), so it's not an uncommon request.
As for using certifi with urllib3, it's outlined in the Security section of the documentation. Here's the main piece:
import urllib3
import certifi
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED', # Force certificate check.
ca_certs=certifi.where(), # Path to the Certifi bundle.
)
# You're ready to make verified HTTPS requests.
try:
r = http.request('GET', 'https://example.com/')
except urllib3.exceptions.SSLError as e:
# Handle incorrect certificate error.
...
Upvotes: 3