Getting Invalid Authorization, Python

Hi,

I have read through a lot of posts and it seems that the way to make a get request is as follows.

image

However this is giving me an invalid authorization error. I have tried having the key with and without the colon. Is there something else I am missing?

Thanks.

There is some information on verifying your access code in this document: Authentication

Thank you for the reply. I did have a look but i didnt find it that helpful. The advice on this forum has been easier to follow but unfortunately hasnt worked

Hello @admarshall2002 Can you check that the API Key you are using is for the ‘Live’ service and that it is currently active. There is a Test service we have at Companies House which is a sandboxed account and has a slightly different Url.

Live Endpoint:
https://api.company-information.service.gov.uk

Test Endpoint:
https://api-sandbox.company-information.service.gov.uk

Below is a code snippet that I used to get a JSON object back.

import requests
company_number = 'XXXXXXXX'
api_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:'
url = 'https://api.company-information.service.gov.uk/company/{company_number}'.format(company_number=company_number)
profile = requests.get(url, auth=(api_key,''))
data = profile.json()
print data
1 Like

Thanks a lot, the url was the problem. :grinning:

Enjoy the rest of your day

Marking with the word “Solved” since this was not mentioned in the documentation upfront for using sandbox url .