0

我正在尝试安装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

任何指针?

4

1 回答 1

1

Python 2.3 不支持装饰器(这就是@classmethod)或列表推导(这是第二个错误),所以你要么必须找到旧版本的海报,要么坚持使用 urllib/urllib2做你的 HTTP 工作。

实际上,Poster 似乎是在 2008 年 7 月左右创建的,所以即使你能找到原始源,也不太可能有支持 Python 2.3 的版本。您至少不能升级到最新的 Python 2.x 有什么特别的原因吗?

于 2009-11-23T04:55:58.563 回答