Closed jimmyswimmy closed 2 years ago
Just like api_limits you can now pass an empty status dict in which the HTTP returncode will be set:
status = {}
result = digikey.product_details('296-6501-1-ND', status=status)
print(status['code'])
See digikey-api 0.6.1
Hi,
In performing digikey.product_details(dk_part_number) operation, I am trying to figure out how to distinguish between a 404 (part not found) and a failure of the API to reach digikey/return anything. The return value in both cases is None.
If I search for e.g. an ancient part like 300-8544-1-ND, the following occurs:
2021-10-28 09:57:14,279 - digikey.v3.api - ERROR: Exception when calling product_details_with_http_info: (404) Reason: Not Found HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 28 Oct 2021 13:57:14 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Server': 'Kestrel', 'X-RateLimit-Limit': '1000', 'X-RateLimit-Remaining': '986', 'Access-Control-Allow-Origin': '', 'Access-Control-Allow-Headers': 'origin, x-requested-with, accept, content-type, authorization,x-digikey-client-id, x-digikey-locale-site, x-digikey-locale-language, x-digikey-locale-currency, x-digikey-locale-shiptocountry, x-digikey-customer-id', 'Access-Control-Max-Age': '3628800', 'Access-Control-Allow-Methods': 'GET, POST', 'X-DIGIKEY-REQUEST-ID': '61455b37-5c98-4c13-c530-f081fe27f53f'}) HTTP response body: {"ErrorResponseVersion":"3.0.0.0","StatusCode": 404,"ErrorMessage":"The specified part was not found.","ErrorDetails":"The specified part 300-8544-1-ND was not found","RequestId":"61455b37-5c98-4c13-c530-f081fe27f53f","ValidationErrors":[]}
On the other hand, I occasionally get a long string of errors similar to this:2021-10-28 09:47:58,750 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000020EB948A688>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')': /Search/v3/Products/300-8555-1-ND
and these also return None after failing.Is there a way to distinguish the two? Or at least get the last status of an API activity to see if it succeeded or failed?
Thank you. I'll post if I find anything of interest.