Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Error Messages, Exceptions, Tracebacks

Error Messages, Exceptions, Tracebacks

錯誤訊息在 Python 世界裡,被稱為 Exception 或 Traceback,這裡整理常見的原因和可能的處理方法。

First Place to Visit

先尋找類似的訊息列表,或是使用「引號符號」指定 exact match 的搜尋結果。錯誤訊息被吃掉的範例。

AttributeError 通常代表欄位變數不存在,常見狀況是透過匯入方式新增表單,資料來源如果是 Null 的話,就可能造成欄位變數不存在,常發生在選項式欄位,不過,有時候也發生在 image 欄位。

AttributeError: 'NoneType' object has no attribute 'tag'

可能是 PIL 沒生效的關係,可改用 Pillow 並留意 3.3.x 版本的問題

"Python.h" No such file or directory

AttributeError: 'NoneType' object has no attribute 'aq_acquire'

使用 plonectl run script.py 執行 invokeFactory 時,這樣的錯誤跟 portal initialization 有關,要搭配前置設定

Products.PortalTransforms: 'NoneType' object has no attribute 'items'

+  if value:
     for key, val in value.items():
       result[key] = val

HTMLParser.HTMLParseError

EOF in middle of construct

檢查 ending quote 是否缺少。

AttributeError: type object 'IThemeSpecific' has no attribute 'isOrExtends'

想要移除 Plone4 之前的 theme 常會遇到這樣的問題,在 ZMI portal_view_customization 出現這個訊息,刪除 plone.app.austomerize 不一定有用,起因來自於 portal_view_customization 存在客製化的舊式程式碼,先把它們移除就行。

ContentProviderLookupError

Nathan Van Gheem updated rev110625 on 2010/02/10 in discussion reported bug and monkey patch at view.py

from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile

def _getContext(self):
    while 1:
        self = self.aq_parent
        if not getattr(self, '_is_wrapperish', None):
            return self

class MyView(BrowserView):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        #Monkey patch for weird error
        ZopeTwoPageTemplateFile._getContext = _getContext

Product.Five.metaclass.SomeView object at ...

http://plone.293351.n2.nabble.com/context-plone-portal-state-vs-context-plone-portal-state-td5824746.html

ImportError: No module named paste.evalexception

No module named paste.evalexception 使用 plone.app.debugtoolbar 除錯

經驗記錄: 1) No module named schema 發現 schema folder 沒有 __init__.py 2) plone.app.imagecropping 新版目標以 5.1 相容 5.0 可能會 ImportError

ImportError: No module named component hooks

在 buildout.cfg 裡加上 zope.app.component getSite collective.addthis

kssValidateField

MultiSelectionWidget kssValidationField

plone.app.z3cform KSS inline validation with custom traversers

TypeError: Can't pickle objects in acquisition wrappers

http://stackoverflow.com/questions/12366274/plone-typeerror-cant-pickle-objects-in-acquisition-wrappers

TypeError: ('object.__new__(ChildSiteDescriptor) is not safe, use Persistence.Persistent.__new__()', ... )

Check if an ending quote is missing.

TypeError: page() takes at least 4 arguments (5 given)

extend-macro must be used with define-macro

Deadlock Issue

ValueError

Unable to find update_version_before_edit: CMFEditions profile steps re-import

invalid literal for int () with base 10

Database Conflict

POSKeyError During Commit ZODB.POSException.ReadConflictError: what sort of conflict rates to expect under torture situations

ReadConflictError class Products.Transience.Transience.Increaser Membrane

Hanno Schlichting: a ConflictError can only be raised during the final transaction.commit() call when data is actually send to the ZEO/ZODB storage. All work that was supposed to be done by the current request will have been done before that. If a ConflictError occurs, the ZPublisher will by default retry the request up to three times, each time redoing all the work starting with parsing the HTTP request into a request object and figuring out what object to call and everything after that. For the catalog we don't get these ConflictErrors as often, as all BTree data structures including Length support storage-side conflict resolution via the _p_resolveConflict API. So the transaction contents get unpickled inside the storage and a new object is created as the result of merging the last committed object with the changes desired from the conflicting one. For BTree.Length this is pretty easy and for buckets rather hard. This conflict resolution can still raise a ConflictError if it cannot combine the objects, for example because all contents from inside a bucket were deleted or a bucket grew too large and was split into two.

ZODB and worker threads: ZODB.POSException.ConnectionStateError

LongRequestLogger

當網站負載越大時,就越容易發生 ConflictError 問題,通常是因為 portal_catalog 執行時,存取同一個物件,這並不是致命的問題,但可能會讓系統變慢。可能的檢查點很多,而且訊息裡的 OID 資訊,可用來追查物件來源:

from ZODB.utils import p64
app._p_jar[p64(oid)]

@@atct_migrator ConflictError: database conflict error (oid 0x45, class Products.CMFUid.UniqueIdGeneratorTool.UniqueIdGeneratorTool) uid_catalog Update Catalog

CMFEdition

Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module Products.CMFPlone.FactoryTool, line 453, in __call__
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 28, in _call
  Module Products.CMFFormController.ControllerBase, line 231, in getNext
  Module Products.CMFFormController.Actions.TraverseTo, line 35, in __call__
ValueError: Unable to find update_version_before_edit

import profile

Member of group with "editor" role not able to save

ImportError: No module named component.hooks

在新版裡,zope.app.component 將要退場,但許多舊模組還是使用它,除了將相依關係改到 zope.component, zope.security, zope.site, zope.componentvocabulary 之外,最簡單的處理方式是在 buildout.cfg 裡加上 zope.app.component

TypeError: get_dist() takes exactly 4 arguments (3 given)

bootstrap.py

KSS z3cform Inline Validation

plone.app.z3cform

http://localhost:8080/mysite/info/one/kss_z3cform_inline_validation
Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module , line 5, in wrapper
  Module kss.core.actionwrapper, line 231, in apply
  Module plone.app.z3cform.kss.validation, line 60, in validate_input
TypeError: int() argument must be a string or a number, not 'list'

KSS getSite Z3CFormValidation

Issues Migration to Plone 4.3

David Glick just removed KSS from Plone and does not know why in dexterity-development list at 2013/05/08.

PicklingError: Can't pickle : import of module plone.app.kss.interfaces failed

PicklingError: <class 'plone.directive.form.schema.Schema'>: attribute ...

ERROR Zope.UnIndex KeywordIndex

unindex_object could not remove documentId 1732905067 from index object_provides. This should not happen.

Reindex Object Fails During FileField to BlobField Migration

ComponentLookupError: (<InterfaceClass plone.keyring.interfaces.IKeyManager>, '')

plone3 to plone4

ConfigurationError: Unknown directive

ZopeXMLConfigurationError: File "/home/marr/Plone432/zinstance/src/my.content/my/content/configure.zcml", line 12.2-12.37
ZopeXMLConfigurationError: File "/home/marr/Plone432/buildout-cache/eggs/plone.app.kss-1.7.1-py2.7.egg/plone/app/kss/configure.zcml", line 7.4-7.34
ZopeXMLConfigurationError: File "/home/marr/Plone432/buildout-cache/eggs/plone.app.kss-1.7.1-py2.7.egg/plone/app/kss/commands/configure.zcml", line 7.4
ConfigurationError: ('Unknown directive', u'http://namespaces.zope.org/kss', u'commandset')

在 my.content/setup.py 有 plone.app.kss 的 requirement,移除後就處理掉。

UID Already Exists in the Index

2014-01-15 11:27:50 ERROR Products.ZCatalog A different document with value '24c5511931694c5e8f310fb6e6bd5870' already exists in the index.'

避免方式是在修改 UID 後,要馬上執行 object reindex 動作。

Copy / Paste of DX-Container with AT-Item leads to duplicate UIDs

PicklingError

Can't pickle <class 'plone.directives.form.schema.Schema'>

index in zc.relation catalog that still reference this interface

Can't pickle <type 'ImplicitAcquirerWrapper'> ValueError: _p_serial must be an 8-character bytes array

Wrap the code in ZODB.serialize where the error occurs into a try..except and call pdb.set_trace() inside the except clause. Looking at the data to be pickled should give you a clue about the content object causing the trouble.

把模組先安裝,再移除,可能是個技巧。

ERROR ZServer uncaptured python exception

ERROR ZServer uncaptured python exception, closing channel(<class 'socket.error'>:[Errno 110] Connection timed out [/usr/lib/python2.7/asynchat.py|handle_read|110] [/home/marr/Plone432/buildout-cache/eggs/Zope2-2.13.21-py2.7.egg/ZServer/medusa/http_server.py|recv|423] [/usr/lib/python2.7/asyncore.py|recv|387])

DateError: Invalid Date

Products.ZCatalog >= 3.0

InvalidObjectReference

collective.geo.contentlocations: "A new object is reachable from multiple databases. Won't try to guess which one was correct!"

This page does not seem to exist…

Template 發生錯誤時,也會造成這項結果,可以取消整塊 METAL 來快速確認,再逐步偵錯。

經驗: custom content type 使用 plone.app.contenttypes RichText behavior,在 plone.app.contenttypes 未安裝的情況下,會造成錯誤。

LocationError: (<Products.Five.metaclass.SimpleViewClass from ...)

Base Class for View: collective.nitf

Forbidden: Form authenticator is invalid.

CSRF Protection 預設包含一個 Cryptographic Token 輸入值,除非主動關閉這項設定

req.disable_csrf_protection()

當 zeoserver.log 發現 (unconnected) disconnected 訊息,也可以試 plone4.csrffixes 安裝。

error while rendering plone.contentviews

經驗記錄: models/mytype.xml 使用 readonly True 欄位,搭配 content.py 定義類似 indexer 函式,能正常執行;如果沒有 readonly 欄位,會讓 plone.contentviews 錯誤。

NotImplementedError: The class deriving from AutoExtensibleForm must have a 'schema' property

collective.auditlog: Plone5 Compatibility

 class AuditAddForm(AddForm):
-    form_fields = form.FormFields(IAuditAction)
+    form_fields = form.FormFields(IAuditAction)  # needed for Plone4 (formlib)
+    schema = IAuditAction  # needed for Plone5 (z3c.form)
     label = u"Add Audit Action"
     form_name = u"Configure element"

ValueError: Cannot find a unique name based on _filename

wildcard.foldercontents

name = safe_unicode(name.lstrip('_'))

AttributeError: 'LazyMap' object has no attribute 'searchResults'

catalog context/portal_catalog;
         results python:catalog.searchResults({
           'portal_type': 'Sinology',

typeerror can't pickle instancemethod objects plone

使用 item.effective = item.created 再 item.reindexObject() 會產生錯誤,使用 item.effective_date = item.created() 就能成功。

ConnectionStateError

重新啟動可能解決,也可能 plone.memoize RAMCache 不當針對 Persistent Object 執行快取。

RuntimeError 保留字

Layout id 無法在 multilingual 直接使用

zc.buildout Version 2.5.3 Error: Couldn't find index page for 'ooxx' (maybe misspelled?)