Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.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

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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.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 如何检查谷歌翻译API的字符数?_Python_Google Cloud Platform_Google Translate_Google Translation Api - Fatal编程技术网

Python 如何检查谷歌翻译API的字符数?

Python 如何检查谷歌翻译API的字符数?,python,google-cloud-platform,google-translate,google-translation-api,Python,Google Cloud Platform,Google Translate,Google Translation Api,我正在使用以下代码使用谷歌翻译API进行翻译 from google.cloud import translate_v2 as translate translate_client = translate.Client(credentials=credentials) # if isinstance(text, six.binary_type): # text = text.decode('utf-8') # Text can also be a sequence of string

我正在使用以下代码使用谷歌翻译API进行翻译

from google.cloud import translate_v2 as translate
translate_client = translate.Client(credentials=credentials)

# if isinstance(text, six.binary_type):
#     text = text.decode('utf-8')

# Text can also be a sequence of strings, in which case this method
# will return a sequence of results for each text.
result = translate_client.translate(
    text, target_language='en')

print(u'Text: {}'.format(result['input']))
print(u'Translation: {}'.format(result['translatedText']))
print(u'Detected source language: {}'.format(
    result['detectedSourceLanguage']))

我怎样才能知道到目前为止还有多少个字符被使用?我有一百万个自由字符

是否尝试将值存储在文件中?每次翻译
n
字符时

  • 从文件中读取
    计数
  • n
  • count
    写回文件

  • 是否尝试将值存储在文件中?每次翻译
    n
    字符时

  • 从文件中读取
    计数
  • n
  • count
    写回文件

  • 即使我不认为有直接的方式来请求此类信息(除了控制台),也有一种方式可以在内部创建警报策略

    您可以设置针对特定数量的请求字节触发的警报策略,并应用1个字符=8位=1个字节

    为此,您应该进入监视->警报->创建新策略->

      ·Resource type: Consumed API
      ·Metric: Request sizes 
      ·Filter -> Service = translate.googleapis.com
    
    并根据需要配置尽可能多的触发器。
    我希望这一切顺利

    即使我不认为有直接的方法来请求此类信息(除了控制台),也有一种方法可以在内部创建警报策略

    您可以设置针对特定数量的请求字节触发的警报策略,并应用1个字符=8位=1个字节

    为此,您应该进入监视->警报->创建新策略->

      ·Resource type: Consumed API
      ·Metric: Request sizes 
      ·Filter -> Service = translate.googleapis.com
    
    并根据需要配置尽可能多的触发器。
    我希望这一切顺利

    嗯,这是我实施的一个变通方法。我想从官方来源获得。还有,我如何计算汉字?@Shawn我们在发送到google api之前将测试和计数存储在我们的日志数据库中,根据我们的日志,计数是18k+,但google账单显示48k+,所以我们正在查看发送给google的其他请求是什么,你有什么解决办法吗it@ThomAFAIK当你翻译一些东西时,输入和输出字符都会被考虑在内。例如,如果发送10000个字符进行翻译,结果文本是11000个字符,那么总数将是21000个字符。好吧,这是我已经实现的一个解决方法。我想从官方来源获得。还有,我如何计算汉字?@Shawn我们在发送到google api之前将测试和计数存储在我们的日志数据库中,根据我们的日志,计数是18k+,但google账单显示48k+,所以我们正在查看发送给google的其他请求是什么,你有什么解决办法吗it@ThomAFAIK当你翻译一些东西时,输入和输出字符都会被考虑在内。例如,如果发送10000个字符进行翻译,结果文本为11000个字符,则总数为21000个字符。