CodexBloom - Programming Q&A Platform

GCP Cloud Functions Timeout scenarios When Using Python with Requests Library

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-16
google-cloud-functions python requests timeout Python

I'm not sure how to approach Hey everyone, I'm running into an issue that's driving me crazy... I've been struggling with this for a few days now and could really use some help. I'm working with a timeout scenario with my Google Cloud Function that's triggered by HTTP requests. I am using the `requests` library to call an external API, but it seems that my function is timing out after 60 seconds, even though the external API responds within that time frame. Here's a snippet of my function: ```python import requests from google.cloud import functions_v1 def my_function(request): url = 'https://api.example.com/data' response = requests.get(url) if response.status_code == 200: return 'Success: ' + response.text else: return 'behavior: ' + str(response.status_code) ``` I've confirmed that the external API is up and running and returning valid responses. I've also checked the logs in GCP and see this message: "Function execution took too long" with a timeout duration of 60 seconds. I tried increasing the timeout setting for the function to 120 seconds, but it doesn't seem to have any effect. I also experimented with using the `timeout` parameter in the `requests.get()` call, like this: ```python response = requests.get(url, timeout=55) ``` However, this didn't resolve the scenario either. It feels like there's an underlying scenario with how Google Cloud Functions handles outgoing requests. Does anyone have insights into how to properly configure the timeout for external API calls in Cloud Functions or if there are known issues with this setup? Any help would be greatly appreciated! For context: I'm using Python on Windows. I'm using Python LTS in this project. What's the best practice here? My development environment is CentOS. Could someone point me to the right documentation?