按照其他人的建议: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/