谷歌应用程序引擎 jsonpickle

发布于 2024-08-16 15:54:56 字数 323 浏览 10 评论 0原文

有人让 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

Has anyone got jsonpickle working on the google app engine? My logs say there is no module but there is a module as sure as you're born. i'm using 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云柯 2024-08-23 15:54:56

我已经成功地将 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))

I have managed to make it work registering django.utils.simplejson as a json encoder/decoder. In this real file index.py class Pizza is encoded and decoded back:

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))
呢古 2024-08-23 15:54:56

正如这篇文章所解释的,jsonpickle< /code> 需要几个底层 JSON 模块之一。我将按如下方式解决问题 - 将以下几行放在需要 jsonpickle 的模块的顶部:

import sys
import django.utils.simplejson
sys.modules['simplejson'] = django.utils.simplejson

这解决了问题:jsonpickle 需要 simplejson (作为 JSON 模块之一)可以使用),但 GAE 将其命名为 django.utils.simplejson,因此您需要对其进行适当的“别名”。

As this post explains, jsonpickle requires one of a few underlying JSON modules. I would fix the issue as follows -- put at the top of your module(s) that need jsonpickle the following few lines:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文