Select to view content in your preferred language

Python script - issues connecting with ArcGIS on semi-regular basis

10-03-2023 12:49 PM
Labels (1)
New Contributor II

Hi all.  I've been tasked with writing a Python script that runs every 5 mins, downloading Surveys from the website to the local server.   I have this working (took me a while...) but I continually get connection errors at certain times of day (2:40am), and they continue for several hours before righting themselves.

I've reproduced this on a separate server: both use Arcgis module (  

Relevant parts..


from arcgis.gis import GIS
# Connect to ArcGIS

logline("Opening GIS, username >" + <xxx> + "<")
    gis_connection = GIS(username=<xxx>, password=<yyy>)
    logline ("Connected OK")
except Exception as e:
            "Error opening GIS connection - Error returned is : >"
            + str(e) + "<" )
My log shows ...
4/10/2023 08:00:43 : Error opening GIS connection - Error returned is : >A connection error has occurred: HTTPSConnectionPool(host='', port=443): Max retries exceeded with url: /sharing/rest/generateToken (Caused by ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)))<
Is this the memory leak problem from this post?
I've introduced a periodic garbage collect as per that post's suggestions, but that didn't seem to help. 
Any other suggestions?   (Do I need to explicitly close the connection to the website at the end of each iteration of the script, for example?)
Thanks for any suggestions...  
0 Kudos
2 Replies
Esri Contributor

Hey Jon,

How are you scheduling your python script? I have seen this issue come up from a user case before.

The resolution to this was scheduling the script from within ArcGIS Pro rather than scheduling it directly with Windows Task Scheduler. 

Hopefully that fixes this for you as well,


Esri UK -Technical Support Analyst
New Contributor II

Thanks David - it was actually easier than that.  The times corresponded exactly with a Veeam backup of that server.   I suspect the issue has always been there and we're only just now detecting it (as this is a new script).    I've got my Systems Veeam people looking at what's happening there.  

I wasn't aware that there was a scheduler within ArcGIS Pro - I'll certainly take a look there too.  However I'm trying to get this place to move to a centralized scheduling location - right now things are scattered in all sorts of places, and introducing another place would be counter-productive to that proposal.  


Thanks again for the attention and suggestion though.