使用urllib3 / requests时出现这种奇怪的“无效语法”错误

时间:2012-11-23 15:44:10

标签: python install 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 btw。

1 个答案:

答案 0 :(得分:2)

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

  
      
  • 在Python 2.6+和Python 3.2 +
  • 上测试   

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

  

删除了Python 2.5支持(在2.6.7,2.7.2上测试)

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

  

捕获异常的备用语法:except TypeError as exc

urllib3现在使用这种语法,但是你试图在不支持它的Python 2.5上运行它。