KeyError: 'No X-Ratelimit-Reset Header in response'

I am using the chwrapper library (GitHub - JamesGardiner/chwrapper: A python wrapper around the Companies House UK API.)

The call is:

search_client = chwrapper.Search(access_token=key)
response = search_client.profile(company_number) 

it is returning this error:

KeyError: 'No X-Ratelimit-Reset Header in response'

Worked fine on the 27th but not today, the 28th.

I have reregistered the application. I get the same behaviour with both keys.

Any help appreciated, thank you.

Summary - check you’re accessing it from a whitelisted IP first e.g. with curl.

Works OK for me. Caveats - I don’t use this wrapper and I’ve not re-registered in the last couple of days. I checked on both the main and the documents API and both return this header.

Quick test with curl:

   curl -uMY_API_KEY_HERE: -I "https://api.companieshouse.gov.uk/company/NF004299"
    
    HTTP/1.1 200 OK
    Date: Thu, 28 Feb 2019 22:33:16 GMT
(... others snipped, then: )
    Access-Control-Allow-Headers: X-RateLimit-Query, origin, content-type, content-length, user-agent, host, accept, authorization
    Access-Control-Expose-Headers: X-RateLimit-Window, X-RateLimit-Limit, X-RateLimit-Remain, X-RateLimit-Reset, Location, www-authenticate, cache-control, pragma, content-type, expires, last-modified
    X-Ratelimit-Limit: 600
    X-Ratelimit-Remain: 599
    X-Ratelimit-Reset: 1551393496
    X-Ratelimit-Window: 5m
    Server: CompaniesHouse

If your query returned an error (e.g. the 403 of late) then these headers aren’t sent:

HTTP/1.1 403 Forbidden
Date: Thu, 28 Feb 2019 22:31:09 GMT
Connection: keep-alive
Server: CompaniesHouse

Or a normal “not found”:

HTTP/1.1 404 Not Found
Content-Length: 19
Content-Type: text/plain; charset=utf-8
Date: Thu, 28 Feb 2019 22:37:47 GMT
Server: nginx/1.12.1
Connection: keep-alive

…so then the wrapper won’t get the headers it was expecting and you’ll see this error.

So even though you said you’d re-registered it might be worth a check, especially that where you’re issuing the request from is in the CH whitelist. I used to be able to access the API from a range of locations which no longer work after the change:

voracityemail,

Thank you very much for the information and your time.
I re-registered as a REST, not streaming app, and white listed our IP.
Working well now.

I am now getting 404 errors on 90% of the calls searching for companies by number. The numbers have been confirmed on the CH website UI so I know they are good. But that is a different issue.

I am now getting 404 errors on 90% of the calls searching for companies by number.

Without examples I wouldn’t know. A speculation - if this occurs when requesting company info e.g. “company profile” or other endpoint (e.g. not the search endpoint) check the actual URI sent to Companies House contains 8 characters - e.g. leading zeros are not being dropped, no spaces before / after:

e.g. if your company is number 09824208 ensure you’re sending
…/company/09824208

and not:

/company/9824208

The entries returned by the API in “links” sections should be correct but if these company numbers are coming from anywhere else don’t assume they’re correct!.

This may be of no consequence to you but I had a quick look at the Python wrapper you’re using and it looks like if CH returns a http error the wrapper will always complain about these headers being missing. It seems that CH do not send these headers if reporting an http error. I’m not a Python coder and this was only a skim read so I maybe wrong!