开发者

django cnotes not working

开发者 https://www.devze.com 2022-12-19 01:52 出处:网络
I have just installed django-cnotes But it wont work. It just throws up this error Traceback (most recent call last):

I have just installed django-cnotes But it wont work. It just throws up this error

Traceback (most recent call last):

File "/Library/Python/2.5/site-packages/django/core/servers/basehttp.py", line 279, in run
self.result = application(self.environ, self.start_response)

File "/Library/Python/2.5/site-packages/django/core/ser开发者_运维百科vers/basehttp.py", line 651, in __call__
return self.application(environ, start_response)

File "/Library/Python/2.5/site-packages/django/core/handlers/wsgi.py", line 245, in __call__
response = middleware_method(request, response)

File "/Library/Python/2.5/site-packages/django_cnote-0.3.4-py2.5.egg/cnotes/middleware.py", line 47, in process_response
signed_data = self.sign('cnotes', base64.urlsafe_b64encode(Pickle.dumps(cnotes.cnotes)))

PicklingError: Can't pickle <class 'django.utils.functional.__proxy__'>: attribute lookup django.utils.functional.__proxy__ failed

And it is not even in the normal django error debug page. What you see above is all there is on the screen.

And I have just used it as described on github, I just dont get it. Any one have an idea for what is causing this?

UPDATE: Okay, so I have found something, I think.

message = _("You have successfully altered ")
message += edituser.username
cnotes.add(message)
message2 = _("You may now close ")
cnotes.add(message2)

This will cause the error. So I thought "Okay, I can only call it once per view" That would have been stupid and it was indeed not the cause.

The following code will produce no error

message = _("You have successfully altered ")
message += edituser.username
cnotes.add(message)
message2 = '_("You may now close ")'
cnotes.add(message2)

But is not because of the translation it uses that fine just 2 lines above, but it has to be something with doing another translation or something. Im lost.


It appears as though pickle is receiving an object of type django.utils.functional.__proxy__. This means either your input is weird, or there is a bug in cnotes.

If there is something wrong with your input to cnotes, you should see it if you take a look at the types of your messages (I used the manage.py shell):

>>> message = _("You have successfully altered ")
>>> message += "Bob Knoblick"
>>> type(message)
<type 'unicode'>
>>> message2 = _("You may now close ")
>>> type(message2)
<type 'unicode'>
>>> 

If your types come back as anything other than unicode or str, I'd dig into your code and figure out where that other type is coming from, or ensure that it can be pickled.

If there is something wrong within cnotes, you should get the same error doing this:

cnotes.add(u'Foo')
cnotes.add(u'Bar')
cnotes.add(u'Baz')

Per the original author:
The translated string, _("You may now close ") was not ending up as a unicode string. One can use this to force unicode before sending to cnotes:

message2 = unicode(_("You may now close "))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号