我繼承了一個Python腳本,拋出了以下錯誤:AttributeError的:「詮釋」對象有沒有屬性「編碼」
root : ERROR Unexpected exception encountered in application 'ImagesForWeb'
Traceback (most recent call last):
File "build/bdist.linux-i686/egg/columbiancommon/scaffolding/consoleapp.py", line 169, in run_safe
self.run(**kwargs)
File "/var/scripts/ImagesForWeb/imagesforweb.py", line 102, in run
gallery = columbiancommon.EllingtonPhotoGallery(configobj = self.cmgr)
File "build/bdist.linux-i686/egg/columbiancommon/ellington/photogallery.py", line 51, in __init__
self.Reload()
File "build/bdist.linux-i686/egg/columbiancommon/ellington/photogallery.py", line 128, in Reload
self.SetStatus(self.status)
File "build/bdist.linux-i686/egg/columbiancommon/ellington/photogallery.py", line 68, in SetStatus
self.SetControl("status", [self.status.encode('utf-8', 'replace')])
AttributeError: 'int' object has no attribute 'encode'
我是很新,Python和還沒有完全開發的調試知道如何解決這個問題的技巧呢。
下面是photogallery.py
的代碼段在上述錯誤refrenced:
def SetStatus(self, status):
"""
Sets the publication status of this photo gallery.
Expects to be set to an integer constant, shortcuts include::
EllingtonPhotoGallery.LIVE
EllingtonPhotoGallery.DRAFT
EllingtonPhotoGallery.DELETED
EllingtonPhotoGallery.UNREVIEWED
"""
if(not isinstance(status, int)):
raise EllingtonMechanizeException("Unexpected status value. Please use a status constant.")
self.status = status
self.SetControl("status", [self.status.encode('utf-8', 'replace')])
這是SetControl方法是scaffolding.py內
def SetControl(self, control_name, control_value_unclean):
"""
Raw access to the mechanize method of setting controls to specific values.
**WARNING** Do not use this unless you have a really good reason to do so-- `EllingtonMechanizeScaffolding.SetControlToValue`
and `EllingtonMechanizeScaffolding.SetControlToValueSafe` are much more elegant solutions.
:Parameters:
- `control_name`: The name of the control you're trying to assign a value to.
- `control_value_unclean`: The value to assign to said control. Either a boolean value,
"""
self.browser[control_name] = control_value_unclean
return True
我相信這是行說self.SetControl("status", [self.status.encode('utf-8', 'replace')])
是拋出錯誤,但我不知道爲什麼錯誤發生。自從6個月前我繼承了代碼以來,代碼一直在運行,並且在我的結尾沒有更改。
任何幫助,將不勝感激。
這不是Python 3.x,因爲Ellington和Django只是Python 2.x。 –
這段代碼似乎不太可能在6個月內保持不變。保存一個奇怪的屬性或'__ {g,s} etattr__' hack使得'self.status = status'和'self.status'表現異常,您在這裏展示的代碼要麼拋出異常,要麼嘗試'.encode'一個對象,它是'int'的一個實例。 – delnan
即使self.status是一個unicode對象,self.status.encode中的'replace'('utf-8','replace')也是邪惡的,因爲它會隱藏一個非常糟糕的「unicode」對象。一個包含一個不成對的替代品。 –