Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在AppEngine中从JSON中免除db.blob_Python_Json_Google App Engine_Gql - Fatal编程技术网

Python 如何在AppEngine中从JSON中免除db.blob

Python 如何在AppEngine中从JSON中免除db.blob,python,json,google-app-engine,gql,Python,Json,Google App Engine,Gql,我正在使用eve pos tracker中引用的jsonGQL版本 我和这个可怜的应用引擎开发者有同样的问题: 当json序列化命中模型中png图像(0x89)的二进制数据时崩溃。我不需要序列化这些数据,所以我想跳过该字段,或者简单地输出类似于的内容 这是处理程序: class FillList(webapp.RequestHandler): def get(self): fills = Fill.all() self.response.headers[

我正在使用eve pos tracker中引用的jsonGQL版本

我和这个可怜的应用引擎开发者有同样的问题:

当json序列化命中模型中png图像(0x89)的二进制数据时崩溃。我不需要序列化这些数据,所以我想跳过该字段,或者简单地输出类似于
的内容

这是处理程序:

class FillList(webapp.RequestHandler):
    def get(self):
        fills = Fill.all()
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(jsonGQL.encode(fills.fetch(100)))
我试过这个:

  elif isinstance(obj, db.Blob):
      return "<binary>"
这是我的解决办法

    elif isinstance(obj, db.Model):
        properties = obj.properties().items()
        output = {}
        for field, value in properties:
            data =  getattr(obj, field)
            if isinstance(data, str):
                # db.Blob inherits from str
                data = data.encode('string-escape')
            output[field] = data
        output['id'] = obj.key().id()
        return output
这是我的解决办法

    elif isinstance(obj, db.Model):
        properties = obj.properties().items()
        output = {}
        for field, value in properties:
            data =  getattr(obj, field)
            if isinstance(data, str):
                # db.Blob inherits from str
                data = data.encode('string-escape')
            output[field] = data
        output['id'] = obj.key().id()
        return output

图像有多大?我使用的技巧是在序列化之前将图像转换为base64。如果需要,有一个直接将base64图像嵌入HTMLI的例子。我不想将图像转换成任何东西,只需直接跳过它。我想重要的是要注意,我正在尝试序列化整个集合(编辑以显示),所以我不确定如何处理单个条目。图像有多大?我使用的技巧是在序列化之前将图像转换为base64。如果需要,有一个直接将base64图像嵌入HTMLI的例子。我不想将图像转换成任何东西,只需直接跳过它。我想重要的是要注意,我正在尝试序列化整个集合(编辑以显示),所以我不确定如何处理单个条目。