Python:mechanize没有属性';文本控件';错误

Python:mechanize没有属性';文本控件';错误,python,linux,ubuntu,command-line,mechanize,Python,Linux,Ubuntu,Command Line,Mechanize,我正在使用一年前编写的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(b

我正在使用一年前编写的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()
运行此代码时,会出现以下错误:

AttributeError:“模块”对象没有属性“TextControl”


怎么了?原作者在这里的意图是什么?当我在google
TextControl
上搜索时,似乎没有任何东西与mechanize相关。我通过
apt get install python mechanize安装mechanize

看起来您使用的不是相同版本的
mechanize
库。查看github中的,我在
\uuuu init\uuuuu.py
中看到了这一点:

__all__ = [
    ...
    'TextControl',
    'TextareaControl',
   ]

所以肯定会有一些
TextControl
。在github中,版本实际上是在中定义的。

查看源代码,您安装的mechanize版本似乎不是您试图运行的代码的正确版本

这一来源:

建议应存在
TextControl
(尽管已弃用)

我建议您删除PythonMechanize(使用apt),而是使用easy_install(或从源代码下载并安装)使用mechanize的更新副本


当然,如果您安装了其他依赖旧版本mechanize的软件包,那么您最好从中获取源代码并加载模块。

您好,有没有办法查看我现在使用的mechanize版本?@SusanMayer:
导入mechanize;mechanize.\uuuu version\uuuu
将返回您当前使用的版本。