0
votes

I've seen this question asked before but none of the answers seem to work for me. I am using python version 2.7.13 In my code I have ..

import base64
import httplib2

Now when I run it on my own pc it works fine, but when I run it on my works p.c. behind a firewall I get ..

Traceback (most recent call last):

File "mail4.py", line 2, in

import httplib2

File "C:\Python27\lib\site-packages\httplib2__init__.py", line 39, in

import urllib

File "C:\mypy\urllib.py", line 1, in

import requests

File "C:\Python27\lib\site-packages\requests__init__.py", line 43, in

import urllib3

File "C:\Python27\lib\site-packages\urllib3__init__.py", line 8, in

from .connectionpool import (

File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 35, in

from .request import RequestMethods>

File "C:\Python27\lib\site-packages\urllib3\request.py", line 10, in >

from .packages.six.moves.urllib.parse import urlencode

ImportError: cannot import name urlencode

I've tried setting proxies.

I've tried uninstalling and re-installing six

Also

from urllib.parse import urlencode

All to no avail ?

2

2 Answers

1
votes

You are (in this case) apparently running Python 2.7.x, however parse module is in urllib package in Python 3.x. In Python 2.x its name was (just) urlparse. Based on that, I'd guess different configuration (mismatch in versions used between Code and/or 3rd party packages and/or python interpreter is behind the problem you're seeing).

EDIT: sorry, I should have also noticed you are looking for urlencode on the last bit. In python 2.7 that is a function in urllib module: from urllib import urlencode.

0
votes

I fixed this issue with installing Werkzeug to <1.0, which removed the contrib module

pip install Werkzeug==0.16.1