How to fix “403 Forbidden” errors when calling APIs using Python requests?

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): import requests url=”http://worldagnetwork.com/” headers = {‘User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like … Read more

Fetch a Wikipedia article with Python

You need to use the urllib2 that superseedes urllib in the python std library in order to change the user agent. Straight from the examples import urllib2 opener = urllib2.build_opener() opener.addheaders = [(‘User-agent’, ‘Mozilla/5.0’)] infile = opener.open(‘http://en.wikipedia.org/w/index.php?title=Albert_Einstein&printable=yes’) page = infile.read()

Apache2 virtualhost 403 forbidden?

I was faced with this issue. But I didn’t like the idea of changing the group of my home directory to www-data. This problem can simply be solved by modifying the configuration file for the virtualHost. Simply configure the Directory tag to include these <Directory “your directory here”> Order allow,deny Allow from all Require all … Read more

“Error 403: access_denied” from Google authentication web api despite google account being owner

To fix this issue for me was this simple: Go to https://console.developers.google.com/ On the top left beside the words “Google APIs” click the project dropdown on the right Ensure that your correct project is selected Click “OAuth consent screen” on the left side of the screen (below “Credentials”) If you have not created a consent … Read more

Django returns 403 error when sending a POST request

Look here https://docs.djangoproject.com/en/dev/ref/csrf/#how-to-use-it. Try marking your view with @csrf_exempt. That way, Django’s CSRF middleware will ignore CSRF protection. You’ll also need to use from django.views.decorators.csrf import csrf_exempt. See: https://docs.djangoproject.com/en/dev/ref/csrf/#utilities Please be advised that by disabling CSRF protection on your view, you are opening a gate for CSRF attacks. If security is vital to you then … Read more