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.
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
TextControlshould 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.