2012-11-23 77 views
1

繼在別人的建議:嘗試安裝請求時,使用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。

回答

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上運行它。

+0

奇怪的是,我也安裝了python 2.7,但它似乎像所有使用python 2.5,我該如何解決? – iCodeLikeImDrunk

+0

您似乎正在使用Windows。我不知道,所以恐怕我不知道答案。在Linux/Mac OS上,我只是用'python2.7'替換'python'或'python2.5'的每一個引用,無論是在我執行的文件還是我用來執行它的命令。 –

+0

刪除所有舊的東西,增加2.7,工作完美。謝謝! – iCodeLikeImDrunk