安装Poster(Python模块)时出错
我正在尝试安装Chris Atlee的Python Poster库,这样我就可以在我的脚本中通过HTTP POST请求上传文件。
在Python 2.3中,当我输入# python setup.py install
时,出现了以下错误。虽然安装过程继续进行,但我之后无法使用>>> import poster
。
byte-compiling build/bdist.linux-x86_64/egg/poster/encode.py to encode.pyc
File "build/bdist.linux-x86_64/egg/poster/encode.py", line 112
@classmethod
^
SyntaxError: invalid syntax
byte-compiling build/bdist.linux-x86_64/egg/poster/streaminghttp.py to streaminghttp.pyc
File "build/bdist.linux-x86_64/egg/poster/streaminghttp.py", line 114
newheaders = dict((k,v) for k,v in req.headers.items()
^
SyntaxError: invalid syntax
byte-compiling build/bdist.linux-x86_64/egg/poster/__init__.py to __init__.pyc
有没有什么建议?
1 个回答
1
Python 2.3 这个版本不支持装饰器(@classmethod 就是一个例子)或者列表推导式(这是第二个错误),所以你要么得找一个更老版本的 Poster,要么就只能用 urllib/urllib2 来处理你的 HTTP 工作。
其实,Poster 是在 2008 年 7 月左右创建的,所以即使你能找到原始代码,也不太可能有支持 Python 2.3 的版本。你有没有什么特别的原因不能升级到最新的 Python 2.x 呢?