How to use API with Python?can anyone help me on this.Thanks

Hello! I know it has been a little while since you posted this but just thought I would try my luck and see if you could help as I am having a similar issue. I am quite new to Python so apologies in advance if I am missing something simple! I have read through a few of these threads and tried some different solutions but still cant figure out what it is that isn’t working. I am trying the below with a rest API and get the error message: {‘error’: ‘Invalid Authorization header’, ‘type’: ‘ch:service’}

from pprint import pprint
from requests.auth import HTTPBasicAuth
import base64
import requests
apiKey = ‘MYKEY:’
keyEncoded = base64.b64encode(bytes(apiKey, ‘utf-8’))
url1 = ‘https://api.companieshouse.gov.uk/company/FC015679
re = requests.get(url1,auth=HTTPBasicAuth(keyEncoded,’’)).json()
pprint(re)

Did you manage to solve your issue? Any help would be much appreciated. Thanks in advance!