[英]google app engine jsonpickle
Has anyone got jsonpickle working on the google app engine? 有没有人让jsonpickle在谷歌应用程序引擎上工作? My logs say there is no module but there is a module as sure as you're born.
我的日志说没有模块,但有一个模块肯定你出生了。 i'm using jsonpickle 0.32.
我正在使用jsonpickle 0.32。
<type 'exceptions.ImportError'>: No module named jsonpickle
Traceback (most recent call last):
File "/base/data/home/apps/xxxxx/xxxxxxxxxxxxxxxxx/main.py", line 4, in <module>
import jsonpickle
I have managed to make it work registering django.utils.simplejson as a json encoder/decoder. 我已经成功地将django.utils.simplejson注册为json编码器/解码器。 In this real file index.py class Pizza is encoded and decoded back:
在这个真正的文件index.py类中,Pizza被编码并解码回来:
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import jsonpickle
class Pizza:
pass
class Example(webapp.RequestHandler):
def get(self):
jsonpickle.load_backend('django.utils.simplejson',
'dumps','loads',ValueError)
encoded = jsonpickle.encode(Pizza())
self.response.out.write( jsonpickle.decode(encoded).__class__ )
run_wsgi_app(webapp.WSGIApplication([('/', Example),],debug=True))
As this post explains, jsonpickle
requires one of a few underlying JSON modules. 正如这篇文章所解释的那样,
jsonpickle
需要一些基础JSON模块。 I would fix the issue as follows -- put at the top of your module(s) that need jsonpickle the following few lines: 我会解决这个问题如下 - 把你需要jsonpickle的模块顶部放在以下几行:
import sys
import django.utils.simplejson
sys.modules['simplejson'] = django.utils.simplejson
This addresses the problem: jsonpickle needs simplejson
(as one of the JSON modules it can use), but GAE has it as django.utils.simplejson
, so you need to "alias" it appropriately. 这解决了这个问题:jsonpickle需要
simplejson
(作为它可以使用的JSON模块之一),但GAE将它作为django.utils.simplejson
,所以你需要适当地“别名”它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.