Python:mechanize 没有属性“TextControl”;错误
我正在使用一年前编写的 Python 代码。
我的操作系统是 Ubuntu 10.10 和 Python 2.6.6。
代码片段是:
import mechanize
.....
br.select_form(nr=0)
br['sign_in[email]'] = username
br['sign_in[password]'] = password
tc = mechanize.TextControl('hidden', 'token', {'value':token})
tc.add_to_form(br.form)
self.submit()
当我运行此代码时,出现此错误:
属性错误:“模块”对象没有属性“TextControl”
有什么问题?原作者的意图是什么?当我谷歌 TextControl
时,似乎没有任何内容与 mechanize 有关。我通过 apt-get install python-mechanize 来安装 mechanize。
I am using Python code which was written one year ago.
My OS is Ubuntu 10.10 with Python 2.6.6.
The code snippet is:
import mechanize
.....
br.select_form(nr=0)
br['sign_in[email]'] = username
br['sign_in[password]'] = password
tc = mechanize.TextControl('hidden', 'token', {'value':token})
tc.add_to_form(br.form)
self.submit()
When I run this code, I get this error:
AttributeError: 'module' object has no attribute 'TextControl'
What is wrong? Whats the original author's intention here? When I google TextControl
, nothing seems to be related with mechanize. I install mechanize by apt-get install python-mechanize
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看源代码,您安装的 mechanize 版本似乎不是您尝试运行的代码的正确版本。
此来源:
https://github.com/jjlee/mechanize/blob/ master/mechanize/__init__.py
建议应该存在
TextControl
(尽管它已被弃用)。我建议您删除 python-mechanize (使用 apt),并通过使用 easy_install (或从源代码下载并安装)来使用较新的 mechanize 副本。
当然,如果您安装了其他依赖于旧版本 mechanize 的软件包,那么您最好获取源代码并从中加载模块。
Looking at the source code, it would appear that the version of mechanize you've got installed is not the correct version for the code you're attempting to run.
This source:
https://github.com/jjlee/mechanize/blob/master/mechanize/__init__.py
suggests that
TextControl
should be present (although it's deprecated).I suggest you remove python-mechanize (using apt), and instead use a newer copy of mechanize by using easy_install (or download and install from source).
Of course, if you've got other packages installed which are relying on the older version of mechanize, you're probably better off getting the source, and loading the module from this.
您似乎没有使用相同版本的
mechanize
库。查看 github 中的 代码,我在__init__.py
:所以肯定应该在某个地方有一些
TextControl
。在github版本中实际上是在_form.py
。It looks like you're not working with the same version of the
mechanize
library. Looking at the code in github, I see this in__init__.py
:So certainly there should be some
TextControl
somewhere. In the github version is actually defined in_form.py
.