gpt4 book ai didi

Python: mechanize has no attribute 'TextControl' 错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:39:25 24 4
gpt4 key购买 nike

我正在使用一年前编写的 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: 'module' object has no attribute 'TextControl'

怎么了?原作者的意图是什么?当我用谷歌搜索 TextControl 时,似乎没有任何内容与 mechanize 相关。我通过 apt-get install python-mechanize 安装 mechanize。

最佳答案

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

此来源:

https://github.com/jjlee/mechanize/blob/master/mechanize/__init__.py

建议 TextControl 应该存在(尽管它已被弃用)。

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

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

关于Python: mechanize has no attribute 'TextControl' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9340958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com