Robert Millard
Robert Millard

Reputation: 73

Problems importing modules. Python version issue?

I am having some problems with the following. I have inherited a .py file that I need to use but I am obviously using a different python version to the author.

from datetime import datetime

import json, requests, os, time, sys

from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

I get these errors;

E1101:Module 'requests.packages' has no 'urllib3' member
E0401:Unable to import 'requests.packages.urllib3.exceptions'

Any help pointing me in the direction of what is wrong would be great.

I am using Python 3.6.4 if that helps.

Upvotes: 2

Views: 3358

Answers (4)

fyqc
fyqc

Reputation: 161

I suffered same issue, and this is what finally worked out on my computer:

requests.urllib3.disable_warnings()

Put this command anywhere after import requests.

Upvotes: 1

shellwhale
shellwhale

Reputation: 902

Here is a straight forward approach

from urllib3 import disable_warnings
from urllib3.exceptions import InsecureRequestWarning
    
VERIFY_HTTPS = False
    
if VERIFY_HTTPS is not True:
    disable_warnings(InsecureRequestWarning)

Upvotes: 0

Calamari
Calamari

Reputation: 29

I realise this is a bit old, but I had the same issue and found that in python3 you can use urllib3

So in your case, instead of: from requests.packages.urllib3.exceptions import InsecureRequestWarning

Use: from urllib3.exceptions import InsecureRequestWarning

Upvotes: 0

Devstr
Devstr

Reputation: 4641

Have you installed requests?

pip3 install --upgrade requests

see How to fix ImportError: No module named packages.urllib3?


There's also another mention of this error here: https://github.com/thp/urlwatch/issues/159

I managed to resolve this problem on Ubuntu 14.04 by uninstalling the system pip (python3-pip) then using easy-install3 to reinstall the latest pip. After that I was able to upgrade requests (which refused to upgrade otherwise). I also needed to manually remove urllib3 and chardet from /usr/lib/python3/dist-packages.

In summary: this problem was caused by using the distribution-installed Python 3, which is running a patched (and outdated) pip that will refuse to upgrade any distro-installed Python packages.

It looks like there's older version of requests installed. On macOS I'd recommend installing python via homebrew to avoid messing with system installation of python.

    brew install python3
    python3 -V
    pip3 install requests

Upvotes: 0

Related Questions