7

I am using python 2.7.12. When i do import requests, I see the error below.

Tried uninstalling & installing requests, upgrading pip as well, but no luck, still same issue.

Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
/home/test/.local/lib/python2.7/site-packages/requests/__init__.py:80: 
RequestsDependencyWarning: urllib3 (1.13.1) or chardet (2.3.0) doesn't match a supported version!
RequestsDependencyWarning)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/test/.local/lib/python2.7/site-packages/requests/__init__.py", line 90, in <module>
from urllib3.exceptions import DependencyWarning
ImportError: cannot import name DependencyWarning

How can I solve this?

Ramon Melo
  • 270
  • 2
  • 9
  • 21
MaYHEM
  • 145
  • 1
  • 3
  • 5
  • Are you downloading a version of requests that works with python 2.7? Based off what it's saying... RequestsDependencyWarning: urllib3 (1.13.1) or chardet (2.3.0) doesn't match a supported version! – J0hn Jul 05 '17 at 13:18

8 Answers8

8

I had the same error and was able to fix it by upgrading requests with the following command:

sudo pip install --upgrade requests
luator
  • 4,769
  • 3
  • 30
  • 51
  • 1
    This solved the issue for me - the error was appearing whenever running Ansible. In my case, Python 3 had no problem with `requests` but Python 2 did, so I ran `sudo pip2 install --upgrade requests` instead. – Tim Malone Apr 19 '18 at 11:19
2

There are two cases that occur this problem.

  1. There is duplicated PATH of pip.

    apt-get remove python-pip

    easy_install pip

  2. This problem is caused by a mismatch between your pip installation and your requests installation.

    You can solve this issue by updating pip.

heltdog
  • 31
  • 6
  • Any other suggestions? I've got the same problem which suddenly appeared overnight. Programs that have been executing without any problem for days suddenly are dying with this error. I'm using python3.5 – Jay Stevens Dec 07 '17 at 14:30
2

In my case, I changed the code like following

  • Open up file: /usr/lib/python2.7/site-packages/pip/__init__.py and find this line.

    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning

  • Check if pip._vendor.request folders are there. If yes, then it must be python path issue. If no, do following.
  • Remove text before urllib3 and change like this.

    from urllib3.exceptions import DependencyWarning

I will also try to make PR request about this.

Andrew Chong
  • 174
  • 1
  • 6
1

If sudo pip install --upgrade requests didn't worked (as in my case) try to uninstall and install requests with no-cache option:

sudo pip --no-cache-dir uninstall requests
sudo pip --no-cache-dir install requests
Megamozg
  • 975
  • 9
  • 15
0

This began happening for me after I installed "awsebcli" via pip, which is a package to support Elastic Beanstalk on AWS for python.

None of the suggested solutions I found online worked and would just result in the same error.

I wound up opening the file mentioned and commenting out the 2 lines about DependencyWarning

#from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
#warnings.filterwarnings("ignore", category=DependencyWarning)  # noqa

Then I was okay again

slashdottir
  • 7,835
  • 7
  • 55
  • 71
0

Just do these steps:

$ sudo pip uninstall requests
$ sudo pip install requests
$ sudo pip uninstall docopt
$ sudo pip install docopt

or

pip install --upgrade --force-reinstall requests
Navi
  • 1,000
  • 1
  • 14
  • 44
0

I managed to fix this issue just by upgrading urllib3:

sudo pip install --upgrade urllib3

Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
-2

None of the above answers work for me (cause whenever I do pip xxx, I got the same exception: cannot import name DependencyWarning), finally I managed to fix Pip by doing this:

easy_install pip

As easy as that ...