I have a website with a form in which a user enters a URL of a youtube video. When the form is "submitted" (actually, an AJAX call is made, which updates the form), the part of the form that's updated via the AJAX call shows a "502 Bad Gateway nginx 1.8" error - this happens when attempting to get youtube data from Google's Youtube API, V3. The code that gets data from the google API is as follows:
def get_youtube_data_via_API(self, video_id, production = False):
try:
if production or self.settings.url in self.request.env.HTTP_HOST:
api_key = ... # production API Key
else:
api_key= ... # testing API key
# generate the API URL
api_url = "https://www.googleapis.com/youtube/v3/videos?id=" + \
str(video_id) + "&key=" + api_key + "&part=snippet"
# get the data
response = requests_get(api_url)
return json_loads(response.text)
except Exception as e:
# print exception and write it to file
I'd appreciate any suggestions as to what could be going wrong here, or on how to diagnose or resolve it. Thanks.