我有一个Google Cloud函数,在其中我使用Python库调用了两个外部requests.get (或requests.post ),一个API和另一个URL。请注意,这些API是使用Postman测试和工作的。
requests.get正在下载一个MP3文件,它在云函数中工作,因为我可以在云存储中看到下载的文件:
download_url = "https://some.url.com/music.mp3"
resp = requests.get(download_url)
[get the resp.content, put to storage bucket]除了存储在云存储中,我还将这个mp3文件发送到Google Cloud Speech- to -Text API,并获得转录后的文本,我想将其发布到另一个网址。
[transcribe the audio using Speech-to-Text API, get the transcibed text]
data = { "download_url": download_url, "transcription": transcribed_text }
upload_api = https://another.url.com/api"
resp = requests.post(upload_api, data = data)同样,转录是有效的,因为我打印/记录文本,并且它显示在Cloud Functions的View Logs控制台中。然而,在requests.post中,我也根据日志获得了一个超时。
requests.post(upload_api, data = data, timeout=120)


我甚至延长了超时设置,但这种情况仍然会发生。对此有何解释?是否有我错过设置的Google Cloud配置可能导致此问题?
发布于 2020-03-24 06:44:12
这是因为GCP云函数有1分钟的超时,为了解决这个问题,必须在创建函数时声明超时限制
如果您正在使用Gcloud CLI命令来部署您的函数,则需要添加标志--timeout
例如
gcloud functions deploy FUNCTION_NAME --timeout=TIMEOUT FLAGS如果您正在使用GCP控制台(Web ),则需要按照此link上的步骤进行操作
https://stackoverflow.com/questions/60782777
复制相似问题