HTTP error 403 on this code:

Beginning to work with api version2…
adjusted a code snippet from the old documentation to python3 and api2 but it doesn’t work, I hit a 403 wall :frowning:
What’s wrong?

import urllib.request
import json


url = ‘

headers={‘Authorization’: 'Token ’ + API_KEY}
req = urllib.request.Request(url, headers=headers)

with urllib.request.urlopen(req) as response:
lang_json =
languages = json.loads(lang_json)
for language in languages:
print (language)

you should try requests library instead:

import requests

print(requests.get(‘’, headers={‘Authorization’: 'Token ’ + API_KEY}).json())

1 Like

Thank you very much, this worked (leaving out the ; after the URL) :slight_smile: