Solved

Cognite Python SDK - Error generating access token: invalid_request, 400, too many calls

  • 27 September 2023
  • 8 replies
  • 84 views

Userlevel 1

Hello,

We have off late moved from Rest calls to SDK and post that we have started seeing the below error

Error generating access token: invalid_request, 400, too many calls

 

What is recommended for this type of error ? Can’t we add a exponential delay at sdk side ?
Also it would be important for us to know that this error is given after how many calls ?
 

icon

Best answer by Murad Sæter 27 September 2023, 14:55

View original

8 replies

Userlevel 2

Hi - is this happening with AzureAD or Sauth?

Userlevel 1

Hi Murad,
Currently I checked on Sauth enabled project.

Userlevel 2

When is this happening? This is Sauth specific, it seems Sauth is doing rate limiting. We haven’t experienced this error with Azure AD.

Userlevel 1

Ok. So is sdk/rest api calling Sauth everytime its getting invoked even if the name of client is same ? anykind of caching being done ? What if you get Client config with same name or same instance of Client Config instead new one each time will there be change in the pattern of calling Sauth ?

Actually we saw below exception on rest endpoint invocation also for Sauth enabled cognite project.

Exception occured in fetch_combined_data method:HTTPSConnectionPool(host='westeurope-1.cognitedata.com', port=443): Max retries exceeded with url: /api/v1/projects/slb-pdf/userapis/spaces/QA_Test_Space/datamodels/QA_PERF_DATA/versions/1/graphql (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f770f7466d0>: Failed to establish a new connection: [Errno 111] Connection refused'))
Userlevel 1

In above case, we saw the error after 30k requests were successful and every this number changes. 

This might be different one altogether not related with Sauth, i think so. But just check

Userlevel 2

If you initialise the client Sauth will be called. The name is just used for reporting purposes in the API. If you initialise only at the start Sauth will only be called when the token needs a refresh (after one hour).

 

The error you pasted above is not related to Sauth, it seems to have been a small hickup on the API side. You could try to tune the retry settings in this SDK using client.config.GlobalConfig:


https://cognite-sdk-python.readthedocs-hosted.com/en/latest/cognite_client.html#cognite.client.config.GlobalConfig.max_retries_connect

Userlevel 1

Ok thanks for your response. One more query 
We are seeing below warnings, can you comment what are they, how is it impacting us and anything that we can do to avoid this

[urllib3.connectionpool] Connection pool is full, discarding connection: westeurope-1.cognitedata.com
Userlevel 1

..

Reply