I believe api.company-information.service.gov.uk is recommended. They both currently work though.
What http response code do you get (I believe this may be response.status_code
in Python)? Any message? Both hosts work fine for me this morning (I’ve snipped some of the JSON response):
curl -u MY_API_KEY_HERE: "https://api.company-information.service.gov.uk/search/companies?q=natwest&items_per_page=3&start_index=0"
{"total_results":140,"items":[{ ... }],"start_index":0,"kind":"search#companies","items_per_page":3,"page_number":1}
curl -u MY_API_KEY_HERE: "https://api.companieshouse.gov.uk/search/companies?q=natwest&items_per_page=3&start_index=0"
{"total_results":140,"items_per_page":3,"page_number":1,"items":[{ ... }],"start_index":0,"kind":"search#companies"}
Is it possibly for you to try this using curl from the environment where you’re trying to run things? I recommend that as it’s probably the simplest way to do this and you can very easily turn on “verbose” mode and see exactly what is being sent, to where, and what is returned.
If the environment where you are running these from is the same then if one runs the other should. If you have registered the IP with Companies House it be fine. You mentioned this being hosted somewhere (presumably not on your own server). In which case I guess it’s possible this may actually be on a server cloud and perhaps the actual IP this is being called from is switching between runs? If you try to call Companies House from an IP not registered to your API key it won’t work.
Not that it should make a difference if you have the same search terms each time but what search term are you using?
Aside / probably unrelated: why are you needing to do the .encode()).decode()
part at the end of the string? (I’m not a Python coder but this seems odd).