Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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 3.x 400呼叫者';s项目没有';不匹配父项目_Python 3.x_Google Cloud Platform_Google Cloud Translate - Fatal编程技术网

Python 3.x 400呼叫者';s项目没有';不匹配父项目

Python 3.x 400呼叫者';s项目没有';不匹配父项目,python-3.x,google-cloud-platform,google-cloud-translate,Python 3.x,Google Cloud Platform,Google Cloud Translate,我有这段代码,它基本上使用CloudTranslateAPI将文本从一种语言翻译成另一种语言。问题是这段代码总是抛出错误:“调用方的项目与父项目不匹配”。有什么问题吗 translation\u separator=“translated\u text:” language\u separator=“检测到的\u语言\u代码:” translate\u client=translate.TranslationServiceClient() #父项=转换\客户端位置\路径( #self.trans

我有这段代码,它基本上使用CloudTranslateAPI将文本从一种语言翻译成另一种语言。问题是这段代码总是抛出错误:“调用方的项目与父项目不匹配”。有什么问题吗

translation\u separator=“translated\u text:”
language\u separator=“检测到的\u语言\u代码:”
translate\u client=translate.TranslationServiceClient()
#父项=转换\客户端位置\路径(
#self.translate\u项目\u id,self.translate\u位置
# )
os.environ[“谷歌应用程序凭据”]=(
os.getcwd()
+“/translator\u credentials.json”
)
#文本也可以是字符串序列,在这种情况下,此方法
#将为每个文本返回一系列结果。
尝试:
结果=str(
翻译客户端。翻译文本(
请求={
“内容”:[正文],
“目标语言代码”:self.target语言代码,
“父”:f'projects/{self.translate_project_id}/'
f'locations/{self.translate_location}',
“模型”:self.translate\u模型
}
)
)
打印(结果)
例外情况除外,如e:
打印(“此处出错>>>”,e)

您的问题似乎与您在应用程序上使用的身份验证方法有关,请使用translate API遵循for authention方法。如果您试图使用代码传递凭据,则可以在代码中显式指向您的服务帐户文件:

另外,还有一个关于使用Python开始使用翻译API的入门指南,这是一个关于使用Python运行翻译API的很好的逐步入门指南


如果问题仍然存在,您可以尝试创建一个针对Google的支持程序

您在哪里运行代码?
def explicit():
    from google.cloud import storage

    # Explicitly use service account credentials by specifying the private key
    # file.
    storage_client = storage.Client.from_service_account_json(
        'service_account.json')