[Zope3-dev] Re: expected string or Unicode object
Jürgen Kartnaller
juergen at kartnaller.at
Tue Dec 5 01:10:13 EST 2006
How should ZODB know how to serialize your xmpp.Client and /or
xmpp.protocol.JID ?
If connectOnStartup is True your code creates these objects.
Jürgen
Florian Lindner wrote:
> Hello,
> everytime I add my utility I get:
>
> 2006-12-04T22:44:26 ERROR SiteError
> http://horus.local:8080/++etc++site/default/+/AddJabberClient.html%3D
> Traceback (most recent call last):
> File "/home/florian/Zope3/src/zope/publisher/publish.py", line 138, in
> publish
> publication.afterCall(request, obj)
> File "/home/florian/Zope3/src/zope/app/publication/browser.py", line 78, in
> afterCall
> super(BrowserPublication, self).afterCall(request, ob)
> File "/home/florian/Zope3/src/zope/app/publication/zopepublication.py", line
> 167, in afterCall
> txn.commit()
> File "/home/florian/Zope3/src/transaction/_transaction.py", line 395, in
> commit
> self._commitResources()
> File "/home/florian/Zope3/src/transaction/_transaction.py", line 495, in
> _commitResources
> rm.commit(self)
> File "/home/florian/Zope3/src/ZODB/Connection.py", line 498, in commit
> self._commit(transaction)
> File "/home/florian/Zope3/src/ZODB/Connection.py", line 543, in _commit
> self._store_objects(ObjectWriter(obj), transaction)
> File "/home/florian/Zope3/src/ZODB/Connection.py", line 570, in
> _store_objects
> p = writer.serialize(obj) # This calls __getstate__ of obj
> File "/home/florian/Zope3/src/ZODB/serialize.py", line 407, in serialize
> return self._dump(meta, obj.__getstate__())
> File "/home/florian/Zope3/src/ZODB/serialize.py", line 416, in _dump
> self._p.dump(state)
> TypeError: expected string or Unicode object, NoneType found
> 127.0.0.1 - - [4/Dec/2006:22:44:26
> +0200] "POST /++etc++site/default/+/AddJabberClient.html%3D HTTP/1.1" 500
> 89 "http://horus.local:8080/++etc++site/default/+/AddJabberClient.html=" "Mozilla/5.0
> (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko)"
>
> I have already tried on zope3-users but got no solution. This is my code:
>
> interfaces.py:
>
> from zope.interface import Interface
> from zope.schema import TextLine, Password, Bool
>
> class IJabberClient(Interface):
> JID = TextLine(
> title = u"Jabber ID",
> description = u"Jabber ID (user at example.com). You need
> to reconnect in order to take effect.",
> required = True )
>
> password = Password(
> title = u"Password",
> description = u"Password for the jabber account",
> required = True )
>
> connectOnStartup = Bool(
> title = u"Connect on startup",
> description = u"Automatically connect when Zope starts
> and also when the object is newly added (what you are about to do).",
> default = True)
>
> jabberclient.py:
>
> from interfaces import IJabberClient
> from zope.interface import implements
>
> from persistent import Persistent
> from zope.app.container.contained import Contained
>
> import xmpp
>
> class JabberClient(Persistent, Contained):
> implements(IJabberClient)
>
> JID = u""
> password = u""
> connectOnStartup = True
>
> status = u"offline"
>
>
> def finishInitialization(self):
> """ Finish the rest of the initialziation that can't be done in
> __init__. """
> if self.connectOnStartup:
> self.setStatus("available")
> else:
> self.setStatus("offline")
>
>
> def setStatus(self, newStatus):
> if self.status == "offline" and newStatus == "available":
> self.jabberID = xmpp.protocol.JID(self.JID)
> self.client = xmpp.Client(self.jabberID.getDomain(), debug=[])
> self.client.connect()
> self.client.auth(self.jabberID.getNode(), self.password)
> self.client.sendPresence(self.jabberID)
>
> if self.status == "available" and newStatus == "offline":
> # disconnect
> pass
>
> self.status = newStatus
>
> def getStatus(self):
> return self.status
>
>
> def onObjectAdded(event):
> if IJabberClient.providedBy(event.object):
> event.object.finishInitialization()
>
>
> configure.zcml
>
> <configure xmlns="http://namespaces.zope.org/zope"
> xmlns:browser="http://namespaces.zope.org/browser">
>
> <class class=".jabberclient.JabberClient">
>
> <require
> permission="zope.ManageServices"
> interface=".interfaces.IJabberClient"
> set_schema=".interfaces.IJabberClient" />
>
> </class>
>
> <browser:addform
> schema=".interfaces.IJabberClient"
> label="Add a JabberClient object"
> content_factory=".jabberclient.JabberClient"
> name="AddJabberClient.html"
> permission="zope.ManageServices"
> set_before_add="JID password connectOnStartup" />
>
> <browser:addMenuItem
> title="Jabber Client"
> class=".jabberclient.JabberClient"
> permission="zope.ManageServices"
> view="AddJabberClient.html" />
>
> <browser:editform
> schema=".interfaces.IJabberClient"
> label="Edit the JabberClient"
> name="edit.html"
> permission="zope.ManageServices"
> menu="zmi_views" title="Edit" />
>
> <subscriber
> for="zope.app.container.interfaces.IObjectAddedEvent"
> handler=".jabberclient.onObjectAdded"
> />
>
> </configure>
>
>
> Sorry for the huge posting but I got no idea where the error comes from. The
> error occurs only when connectOnStartup is True.
>
> Thanks for any help,
>
> Florian
More information about the Zope3-dev
mailing list