Python 3 Requests Module Error: urllib3 version parsing issue

Python 3 Requests Module Error: urllib3 version parsing issue

我正在尝试在 Python 中导入和使用请求 3. 当我导入请求时,我在 IDLE(以及 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)

我已经阅读并了解到,在尝试读取需要三个值来解压(主要、次要、补丁)的 urllib3 版本时,请求存在问题。但是,我的 urllib3 版本是 1.22,最后没有附加补丁。这是我的 pip 冻结:

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

编辑:我找到了一个临时的变通解决方案并作为我的问题的答案发布。但是欢迎/鼓励任何其他更好的解决方案的答案。谢谢。

为了让请求工作,我能够在我的项目/IDLE 会话顶部找到一个解决方法,如下所示:

import urllib3  # Must append a third value to avoid error
if len(urllib3.__version__.split('.')) < 3:
urllib3.__version__ = urllib3.__version__ + '.0'

访问 this link 后,我能够确认在撰写本文时没有 urllib3 1.22 版的补丁。我假设当补丁发布时,这个解决方法将不是必需的,但这可能会帮助遇到类似问题的人。