I'm trying to import and use requests in Python 3. When I import requests I get this error in IDLE (as well as IntelliJ):
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import requests
File "/usr/local/lib/python3.6/site-packages/requests/__init__.py", line 49, in <module>
major, minor, patch = urllib3.__version__.split('.')[:3]
ValueError: not enough values to unpack (expected 3, got 2)
I've read and understand that there is an issue with requests when trying to read the version of urllib3 which needs three values to unpack (major, minor, patch). However, my version of urllib3 is 1.22 with no patch appended at the end. Here is my pip freeze:
appnope==0.1.0
beautifulsoup4==4.6.0
bleach==2.0.0
certifi==2017.7.27.1
chardet==3.0.4
chromedriver==2.24.1
cycler==0.10.0
Cython==0.26.1
decorator==4.1.2
entrypoints==0.2.3
facebook-sdk==2.0.0
geopy==1.11.0
glob2==0.6
html5lib==0.999999999
idna==2.6
ipykernel==4.6.1
ipython==6.1.0
ipython-genutils==0.2.0
ipywidgets==7.0.0
jedi==0.10.2
Jinja2==2.9.6
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.1.0
jupyter-console==5.2.0
jupyter-core==4.3.0
MarkupSafe==1.0
matplotlib==2.0.2
mistune==0.7.4
nbconvert==5.3.1
nbformat==4.4.0
nltk==3.2.4
nose==1.3.7
notebook==5.0.0
numpy==1.13.1
olefile==0.44
opencv-python==3.3.0.10
pandas==0.20.3
pandocfilters==1.4.2
pexpect==4.2.1
pickleshare==0.7.4
Pillow==4.2.1
prompt-toolkit==1.0.15
ptyprocess==0.5.2
Pygments==2.2.0
PyMySQL==0.7.11
pyparsing==2.2.0
python-dateutil==2.6.1
pytz==2017.2
pyzmq==16.0.2
qtconsole==4.3.1
requests==2.18.4
requests2==2.16.0
scikit-learn==0.19.0
scipy==0.19.1
selenium==3.6.0
simplegeneric==0.8.1
six==1.10.0
sklearn==0.0
terminado==0.6
testpath==0.3.1
tornado==4.5.2
traitlets==4.3.2
tzlocal==1.4
urllib3==1.22
virtualenv==15.1.0
wcwidth==0.1.7
webencodings==0.5.1
widgetsnbextension==3.0.2
xlrd==1.1.0
EDIT: I've found a temporary workaround solution and posted as an answer to my question. But any other answers for better solutions are welcome / encouraged. Thanks.
In order to get requests to work, I was able to find a workaround at the top of my project / IDLE session which is as follows:
import urllib3 # Must append a third value to avoid error
if len(urllib3.__version__.split('.')) < 3:
urllib3.__version__ = urllib3.__version__ + '.0'
After visiting this link I was able to confirm there is no patch to urllib3 version 1.22 at the time of this writing. I assume when a patch is released this workaround will not be necessary, but this may help somebody with a similar issue.