{"id":996,"hash":"6f145e73fcbea9b7f6042993ccea7f79da3430252eeb23fe59189a25114709c2","pattern":"How can I fix &quot;403 Forbidden&quot; errors when calling APIs using Python &#39;Requests&#39;?","full_message":"I needed to parse a site, but I got a 403 Forbidden error.\n\nHere is the code:\n\nurl = 'http://worldagnetwork.com/'\nresult = requests.get(url)\nprint(result.content.decode())\n\nThe output is:\n\n<html>\n<head><title>403 Forbidden</title></head>\n<body bgcolor=\"white\">\n<center><h1>403 Forbidden</h1></center>\n<hr><center>nginx</center>\n</body>\n</html>\n\nWhat is the problem?","ecosystem":"pypi","package_name":"python-requests","package_version":null,"solution":"It seems the page rejects GET requests that do not identify a User-Agent. I visited the page with a browser (Chrome) and copied the User-Agent header of the GET request (look in the Network tab of the developer tools):\n\nimport requests\nurl = 'http://worldagnetwork.com/'\nheaders = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}\nresult = requests.get(url, headers=headers)\nprint(result.content.decode())\n\n# <!doctype html>\n# <!--[if lt IE 7 ]><html class=\"no-js ie ie6\" lang=\"en\"> <![endif]-->\n# <!--[if IE 7 ]><html class=\"no-js ie ie7\" lang=\"en\"> <![endif]-->\n# <!--[if IE 8 ]><html class=\"no-js ie ie8\" lang=\"en\"> <![endif]-->\n# <!--[if (gte IE 9)|!(IE)]><!--><html class=\"no-js\" lang=\"en\"> <!--<![endif]-->\n# ...","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/38489386/how-can-i-fix-403-forbidden-errors-when-calling-apis-using-python-requests","votes":166,"created_at":"2026-04-19T04:52:09.111460+00:00","updated_at":"2026-04-19T04:52:09.111460+00:00"}