# Getting Invalid Authorization, Python

**URL:** <http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227>\
**Category:** API Question\
**Created:** [August 2, 2021, 3:22pm UTC](http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227 "2021-08-02T15:22:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![admarshall2002](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@admarshall2002](http://forum.companieshouse.gov.uk/u/admarshall2002)\
**Post date:** [August 2, 2021, 3:22pm UTC](http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227/1 "2021-08-02T15:22:35Z")

</div>

Hi,

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

![image](http://discourselive.s3.dualstack.eu-west-1.amazonaws.com/original/2X/3/33a881943892ddf30e4d4a98bf5db4a749ede9d8.png)

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.

---

<div class="post-metadata">

**Author:** ![lgeorge](http://forum.companieshouse.gov.uk/user_avatar/forum.companieshouse.gov.uk/lgeorge/32/457_2.png) [@lgeorge](http://forum.companieshouse.gov.uk/u/lgeorge)\
**Post date:** [August 3, 2021, 9:46am UTC](http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227/2 "2021-08-03T09:46:02Z")

</div>

There is some information on verifying your access code in this document: [Authentication](https://developer.company-information.service.gov.uk/authentication)

---

<div class="post-metadata">

**Author:** ![admarshall2002](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@admarshall2002](http://forum.companieshouse.gov.uk/u/admarshall2002)\
**Post date:** [August 3, 2021, 10:01am UTC](http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227/3 "2021-08-03T10:01:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dlewis2](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@dlewis2](http://forum.companieshouse.gov.uk/u/dlewis2)\
**Post date:** [August 3, 2021, 10:43am UTC](http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227/4 "2021-08-03T10:43:00Z")

</div>

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](https://api.company-information.service.gov.uk)

Test Endpoint:  
[https://api-sandbox.company-information.service.gov.uk](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
```

---

<div class="post-metadata">

**Author:** ![admarshall2002](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@admarshall2002](http://forum.companieshouse.gov.uk/u/admarshall2002)\
**Post date:** [August 3, 2021, 10:51am UTC](http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227/5 "2021-08-03T10:51:51Z")

</div>

Thanks a lot, the url was the problem. 😀

Enjoy the rest of your day

---

<div class="post-metadata">

**Author:** ![arvind.das](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@arvind.das](http://forum.companieshouse.gov.uk/u/arvind.das)\
**Post date:** [August 3, 2021, 11:00am UTC](http://forum.companieshouse.gov.uk/t/getting-invalid-authorization-python/4227/6 "2021-08-03T11:00:24Z")

</div>

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