小编dha*_*man的帖子

如何将 Google 客户端视觉库响应转换为 Json

我正在尝试将来自 Google Cloud Vision API 客户端库的响应转换为 json 格式。但是我收到以下错误:

AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' 对象没有属性 'DESCRIPTOR

资源

from flask_restful import Resource
from flask import request
from flask import json
from util.GoogleVision import GoogleVision
from util.Convert import Convert

import base64
import requests

import os


class Vision(Resource):

    def post(self):

        googleVision = GoogleVision()

        req = request.get_json()

        url = req['url']

        result = googleVision.detectLabels(url)

        return result
Run Code Online (Sandbox Code Playgroud)

谷歌视觉.py

import os

from google.cloud import vision
from google.cloud.vision import types
from google.protobuf.json_format import MessageToJson

class GoogleVision():

    def detectLabels(self, uri):

        client = vision.ImageAnnotatorClient() …
Run Code Online (Sandbox Code Playgroud)

python json google-api protocol-buffers google-cloud-vision

3
推荐指数
1
解决办法
2949
查看次数

将数据帧 to_csv 文件缓冲区上传到 Google Cloud Storage 时出现 UnicodeError

 UnicodeEncodeError: \'latin-1\' codec can\'t encode character \'\\u2019\' in position 26612: Body (\'\xe2\x80\x99\') is not valid Latin-1. Use body.encode(\'utf-8\') if you want to send it encoded in UTF-8.\n
Run Code Online (Sandbox Code Playgroud)\n\n

我使用df.to_csv带有编码集的方法创建了一个 CSV 文件。尽管如此,我在将文件上传到 Google Cloud Storage 时收到上述错误。

\n\n
json_data = [\n    {\n      "Critics": "Like many of the landmark films of the 1980s, I had watched Mani Ratnam\\u2019s breakout hit \\u201cMouna Ragam\\u201d at a time when I hadn\\u2019t yet crossed paths with ideas like feminism and gender equality. Though I retained …
Run Code Online (Sandbox Code Playgroud)

python unicode pandas google-cloud-platform

2
推荐指数
1
解决办法
1726
查看次数

无法使用 GCloud CLI 迁移到其他服务版本

我看过文档说该gcloud app versions migrate操作可以将流量迁移到另一个版本,但它不能。错误描述似乎说了一些信息,但对我没有帮助。在GCP控制面板上,版本迁移工作正常。这是怎么回事?

 $ gcloud app versions migrate 20190122-120543-ebbfbc9 -s q
 Migrating all traffic from version [q/20190129-164614-09e8288] to 
 [q/20190122-120543-ebbfbc9]
 Do you want to continue (Y/n)?

 ERROR: (gcloud.app.versions.migrate) Issues migrating all traffic of service(s): [q]

 INVALID_ARGUMENT: Invalid request.
 - '@type': type.googleapis.com/google.rpc.BadRequest
   fieldViolations:
   - description: Warmup requests must be enabled for all versions that will gain additional
       traffic as a result of the traffic migration.
     field: service.split.allocations[20190122-120543-ebbfbc9]
Run Code Online (Sandbox Code Playgroud)

google-app-engine command-line-interface google-cloud-platform gcloud

2
推荐指数
1
解决办法
692
查看次数