错误的请求错误400 google api for translation python

错误的请求错误400 google api for translation python,python,google-translate,Python,Google Translate,调用API并获得错误需要从英语翻译成法语,但得到这个错误,所以我使用了这个代码,但它不能正常工作 代码: 错误 回溯(最近一次呼叫最后一次): 文件“trail.py”,第19行,在 main() 文件“trail.py”,第15行,在main中 q=“花” 文件“build/bdist.linux-i686/egg/oauth2client/_helpers.py”,第133行,在位置包装中 文件“build/bdist.linux-i686/egg/googleapiclient/http.

调用API并获得错误需要从英语翻译成法语,但得到这个错误,所以我使用了这个代码,但它不能正常工作

代码:

错误

回溯(最近一次呼叫最后一次):
文件“trail.py”,第19行,在
main()
文件“trail.py”,第15行,在main中
q=“花”
文件“build/bdist.linux-i686/egg/oauth2client/_helpers.py”,第133行,在位置包装中
文件“build/bdist.linux-i686/egg/googleapiclient/http.py”,第840行,在execute中
GoogleAppClient.errors.HttpError:

使用新的谷歌云客户端库,使用服务帐户凭据JSON授权您的API,并调用
导出谷歌应用程序凭据=您的服务。JSON
,而不是使用API密钥。您还可以通过调用
gcloud auth application default login
使用默认应用程序凭据

中演示了这一点,这也将帮助您更快地开始


请注意,translate API需要计费,因为,因此请准备为您的项目设置此功能。

它要求启用计费是否必要它要求启用计费是否必要@classYes。您必须为某些高级API功能启用计费。
from __future__ import print_function

__author__ = 'jcgregorio@google.com (Joe Gregorio)'

from googleapiclient.discovery import build


def main():

  service = build('translate', 'v2',
            developerKey='AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0')
  print(service.translations().list(
      source='en',
      target='fr',
     q="flower"
    ).execute())

if __name__ == '__main__':
  main()
Traceback (most recent call last):
  File "trail.py", line 19, in <module>
    main()
  File "trail.py", line 15, in main
    q="flower"
  File "build/bdist.linux-i686/egg/oauth2client/_helpers.py", line 133, in positional_wrapper
  File "build/bdist.linux-i686/egg/googleapiclient/http.py", line 840, in execute
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/language/translate/v2?q=flower&source=en&alt=json&target=fr&key=AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0 returned "Bad Request">