python - 使用 urllib3/requests 时出现奇怪的 "invalid syntax"错误

标签 python installation python-requests urllib3

按照其他人的建议:Given a big list of urls, what is a way to check which are active/inactive?

尝试使用 urllib3 安装请求时出现错误。

正在尝试安装请求。

C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop>setup.py install
Traceback (most recent call last):
  File "C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop\setup.py", line 6, in <module>
    import requests
  File "C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop\requests\__init__.py", line 52, in <module>
    from . import utils
  File "C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop\requests\utils.py", line 22, in <module>
    from .compat import parse_http_list as _parse_list_header
  File "C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop\requests\compat.py", line 95, in <module>
    from .packages import chardet
  File "C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop\requests\packages\__init__.py", line 3, in <module>
    from . import urllib3
  File "C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop\requests\packages\urllib3\__init__.py", line 16, in <module>
    from .connectionpool import (
  File "C:\Users\yao\Desktop\My Downloads\requests-develop\requests-develop\requests\packages\urllib3\connectionpool.py", line 434
    except Empty as e:
                  ^
SyntaxError: invalid syntax

尝试使用 urllib3。

C:\Users\yao\Desktop\ad stuff\find urls>reqs.py
Traceback (most recent call last):
  File "C:\Users\yao\Desktop\ad stuff\find urls\reqs.py", line 1, in <module>
    import re, csv, urllib3
  File "build\bdist.win32\egg\urllib3\__init__.py", line 16, in <module>
  File "C:\Python25\lib\site-packages\urllib3-dev-py2.5.egg\urllib3\connectionpool.py", line 435
    except Empty as e:
                  ^
SyntaxError: invalid syntax

最近刚刚安装了 setuptools、pip、requests、urllib3。以该顺序。我是不是搞砸了什么?顺便说一句,使用 python 2.5。

最佳答案

urllib3 需要 Python 2.6 或更高版本。来自 their README :

  • Tested on Python 2.6+ and Python 3.2+

他们放弃了对 Python 2.5 的支持 in version 1.2, which was released in January 2012 :

Dropped Python 2.5 support (tested on 2.6.7, 2.7.2)

Python 2.6 添加了处理异常的新语法,您可以在 What’s New in Python 2.6 中读到。 :

Alternate syntax for catching exceptions: except TypeError as exc.

urllib3 现在使用此语法,但您尝试在不支持它的 Python 2.5 上运行它。

关于python - 使用 urllib3/requests 时出现奇怪的 "invalid syntax"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13532163/

相关文章:

visual-studio-2005 - "Could not find file"其中文件绝对、绝对、完全、完全确定地存在

python - 请求发布的依赖于操作系统的行为

python-2.7 - Python 请求 : How can I properly submit a multipart/form POST using a file name

python selenium 无法清除输入字段

python - Python 中嵌套列表的算术运算

python - "Mini Keras"有没有办法在没有整个 keras 包的情况下从训练有素的 keras 模型中获得预测?

ios - 在越狱的 iDevice 上以编程方式卸载应用程序

java - 生成器是否不如 "real"协程?

python - docker镜像中的pip卡住与本地安装的结果不同

python - 使用多核的 Pip 构建选项