有没有人让jsonpickle在谷歌应用引擎上工作?我的日志说没有模块,但有一个模块肯定你出生了。我正在使用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
答案 0 :(得分:4)
我设法将 django.utils.simplejson 注册为json编码器/解码器。在这个真正的文件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))
答案 1 :(得分:3)
正如this post所解释的那样,jsonpickle
需要一些基础JSON模块。我会解决这个问题如下 - 把你需要jsonpickle的模块顶部放在以下几行:
import sys
import django.utils.simplejson
sys.modules['simplejson'] = django.utils.simplejson
这解决了这个问题:jsonpickle需要simplejson
(作为它可以使用的JSON模块之一),但是GAE将它作为django.utils.simplejson
,所以你需要对其进行“别名”。