I've found some similar questions on stackoverflow (1,2,3), but none of them solved my problem.
The URL is something like "https://example.com/api.php?foo=bar". Using the following command will get a json string:
curl "https://example.com/api.php?foo=bar"
while using the following code returns a 502 response (bad gate way):
import requests
requests.get("https://example.com/api.php?foo=bar")
Currently I'm using the following code as a workaround, but I'd like to know why requests.get() doesn't work.
import subprocess
subprocess.check_output(['curl','-s','https://example.com/api.php?foo=bar'])