google.auth.exceptions.DefaultCredentialsError - 不是有效的 json 文件

Mar*_*rci 5 python google-cloud-platform

我没有尝试使用 goole Vision api,但我无法运行我的 python 脚本而不出现以下错误:

google.auth.exceptions.DefaultCredentialsError: ('File /root/GoogleCloudStaff/apikey.json is not a valid json file.', ValueError('Invalid control character at: line 5 column 37 (char 172)',))
Run Code Online (Sandbox Code Playgroud)

我的Python脚本:

import io
from google.cloud import vision

vision_client = vision.Client()
#file_name = "/var/www/FlaskApp/FlaskApp/static/"#'375px-Guido_van_Rossum_OSCON_2006_cropped.png'

file_name = '1200px-Guido_van_Rossum_OSCON_2006.jpg'

#file_name = "/var/www/FlaskApp/FlaskApp/static/cyou_pic_folders/cyou_folder_2017_11_16_10_26_18/pi_pic_lc_2017_11_16_10_26_1800049.png"

with io.open(file_name, 'rb') as image_file:
    content = image_file.read()
    image = vision_client.image(
        content=content, )

labels = image.detect_labels()
for label in labels:
    print(label.description)
Run Code Online (Sandbox Code Playgroud)

非常感谢!

Ric*_*lev 1

DefaultCredentialsError 表示您未能获取默认凭据。您是否以正确的方式完成了初始设置?看看愿景