I wrote a script to call an API and ran it successfully last week. This week, it won't run. I get back the following error message:
Traceback (most recent call last):
File "user_audit.py", line 2, in <module>
import requests
File "c:\Python27\lib\site-packages\requests\__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "c:\Python27\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
I've confirmed that packages is up to date, tried uninstalling and reinstalling it, but nothing has worked so far. Can someone help?
ADDENDUM
I installed urllib3 as suggested by @MSHossain, but then got another error message. The new message referenced another file that I'd written, which had created a Python compiled file. The other file was using smptlib to attempt to send an email. I don't understand how this would happen, but I deleted the other file and my script ran without any problems. I've accepted the answer below as I was able to pip install urllib3, but it should have already been included in the requests module.
The urllib3 module is a powerful, sanity-friendly HTTP client for Python. It supports thread safety, connection pooling, client-side SSL/TLS verification, file uploads with multipart encoding, helpers for retrying requests and dealing with HTTP redirects, gzip and deflate encoding, and proxy for HTTP and SOCKS.
How to check my urllib3 version on Windows? To check which version of urllib3 is installed, use pip show urllib3 or pip3 show urllib3 in your Windows CMD, command line, or PowerShell.
urllib3 is a third-party package (i.e., not in CPython's standard library). Despite the name, it is unrelated to the standard library packages, and there is no intention to include it in the standard library in the future.
The PoolManager class automatically handles creating ConnectionPool instances for each host as needed. By default, it will keep a maximum of 10 ConnectionPool instances. If you're making requests to many different hosts it might improve performance to increase this number: >>> import urllib3 >>> http = urllib3.
Either urllib3 is not imported or not installed.
To import, use
import urllib3
at the top of the file. To install write:
pip install urllib3
into terminal.
It could be that you did not activate the environment variable correctly. To activate the environment variable, write
source env/bin/activate
into terminal. Here env
is the environment variable name.
pip install urllib3
The reason it broke is that I had installed an incompatible version of urllib3
as a transient dependency of awscli
. You'll see such conflicts when you rerun the install.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With