Connection Errors exceptions when running Python scripts

Solved
CBurkhead
Building a reputation

Connection Errors exceptions when running Python scripts

Since early yesterday (9/10), I have been seeing many of my scripts getting Connection error exceptions thrown (requests.exceptions.ConnectionError) when trying to access endpoints. These are Python scripts using the requests library, not the SDK. This has been very random. Sometimes they will error immediately when trying to get the organization list, or whatever the first endpoint call is. Sometimes they will start and then errors will occur during the run through the rest of the script execution. Sometimes they will start erroring during execution for a few calls and then start working again, executing the same calls that were thrown the exception. Sometimes they work just fine.

 

I am accessing the API via api.meraki.com and my header is: {'X-Cisco-Meraki-API-Key':apikey, 'Accept':'application/json', 'Content-Type':'application/json'}

 

Has anyone been seeing anything similar? Is there another URL I should be using, besides api.meraki.com? 

1 Accepted Solution
CBurkhead
Building a reputation

That is helpful to know and the error is pretty much the same, but those postings are from 5 years ago. I have been running the current version of requests since it was released 2 months ago, and did not run into this problem until just last week. I also tried installing the the previous version of requests to see if it made a difference and it did not. One of the packages that they recommend installing, PyOpenSSL is not even supported by requests anymore. 

 

I did check my version of OpenSSL, and upgraded that to the latest version, but that did not help, either. My other searches for errors like this haven't given me anything more recent than 2019.

 

I have gotten around the problem by changing my exception handling and doing retries on the request if this exception is thrown. That is working at present and is allowing my scripts to run normally. I will continue to try and figure this out, but for now the main issue has been taken care of. 

 

Thanks for all of the help!

View solution in original post

5 Replies 5
sungod
Head in the Cloud

The API service is not 100% reliable.

 

From experience, it's failry common to have transient/one-off failures.

 

Others may continue for hours, days, or even months - there's at least one V1 endpoint that stopped working in January, it still doesn't work, I have a case open for this, Meraki say it's not a priority to fix it!

 

You can code to handle transient failures with delay-retry loops, for long term ones you can try using the equivalent V0 endpoint instead (assuming there is one).

 

If something has just started failing and it is persistent, I suggest open a case, at least then it will be known, it may then get fixed, there was an issue with some shards a couple of weeks back, it was resolved in a few days.

PhilipDAth
Kind of a big deal
Kind of a big deal

What, exactly, is the HTTP status code you are getting?

 

I haven't had reliability problems myself.  A real common one that catches out people using requests directly is the 429 return code - meaning you are making requests (quite possibly correct requests) too fast and you need to slow down the rate you are making them at.

429's often seem random if you are making requests at close to the API rate limit.

 

When you use the SDK it handles this automatically for you and re-submits the request.

 

 

So to start - you need to look at the status code being return.

CBurkhead
Building a reputation

There is not actual HTTP status code being returned. This is a thrown exception during the API call, so the variable receiving the data does not even exist when looking in the debugger since it is being created with the call to the requests library. The following are the messages that come back from the exception. Both are from the same script on different runs. As you can see from the messages, the exception is on different API calls, but overall is the same error.

 

HTTPSConnectionPool(host='api.meraki.com', port=443): Max retries exceeded with url: /api/v1/organizations/582090251837636617/inventoryDevices?perPage=1000 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))

 

HTTPSConnectionPool(host='api.meraki.com', port=443): Max retries exceeded with url: /api/v1/organizations (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))

I'm not sure.  Googling and I can find other people having this error in general.  Is this of any help?

https://stackoverflow.com/questions/33410577/python-requests-exceptions-sslerror-eof-occurred-in-vio... 

CBurkhead
Building a reputation

That is helpful to know and the error is pretty much the same, but those postings are from 5 years ago. I have been running the current version of requests since it was released 2 months ago, and did not run into this problem until just last week. I also tried installing the the previous version of requests to see if it made a difference and it did not. One of the packages that they recommend installing, PyOpenSSL is not even supported by requests anymore. 

 

I did check my version of OpenSSL, and upgraded that to the latest version, but that did not help, either. My other searches for errors like this haven't given me anything more recent than 2019.

 

I have gotten around the problem by changing my exception handling and doing retries on the request if this exception is thrown. That is working at present and is allowing my scripts to run normally. I will continue to try and figure this out, but for now the main issue has been taken care of. 

 

Thanks for all of the help!

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.