2012-02-18 42 views
1

我正在使用一年前編寫的Python代碼。Python:mechanize沒有屬性'TextControl'錯誤

我的操作系統是Python 2.6.6的Unbuntu 10.10。

的代碼片段是:

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,沒有什麼似乎與機械化有關。我通過apt-get install python-mechanize安裝機械化。

回答

0

看看源代碼,看起來您安裝的機械化版本不是您嘗試運行的代碼的正確版本。

此來源:

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

表明TextControl應當存在(雖然它的建議使用)。

我建議你刪除python-mechanize(使用apt),而是使用easy_install(或從源代碼下載並安裝)使用更新的機械化副本。

當然,如果你已經安裝了依賴舊版機械化的其他軟件包,你可能會更好地獲取源代碼,並從中加載模塊。

+0

HI有沒有辦法查看我現在使用的機械化版本? – 2012-02-18 12:27:02

+0

@SusanMayer:'進口機械化; mechanize .__ version__'將會返回你當前使用的版本。 – unutbu 2012-02-18 12:52:53

0

它看起來像你沒有使用mechanize庫的相同版本。看着在GitHub上的code,我看到這個__init__.py

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

所以肯定要有一定的TextControl地方。在github版本中實際定義在_form.py

相關問題