arcgis.gis log off?

812
2
03-17-2021 12:39 PM
MingHome
New Contributor III

I have a python script running on schedule every 10 minutes or so to check something in our AGOL.  I use the arcgis.gis module as below.

from arcgis.gis import GIS
gis = GIS('portalURL', user, 'password')

The script in running every 10 minutes. However, some times, not all time, I receive error of "Your request has timed out. (code 504)" or "Too many invalid logins. Please try again later. (Error Code: 400) ". I suspect that it takes too long to log into our AGOL. My question is: Is there a method to "log off" gis? Or should I simply set the gis = None will resolve this?

 

Thanks,

Ming

0 Kudos
2 Replies
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Signing in every 10 minutes by the same user seems a little bit wasteful from the server perspective, because every time it will go through the authentication and authorization process and generate a new token when the previous tokens are still valid...

Just some thoughts for further research:

It may be worth it to keep the state of the GIS object somehow, but the GIS object can't be serialized using json.dumps(gis)... 

How about running an application with an endless loop?  you can delay the execution for 10 minutes in every loop instead of scheduling the execution using a third party software.

 

MingHome
New Contributor III

Thanks and agree! However, currently the burden is on ESRI side, not much on me. 😋

Your mention about the service token reminded me that I was using "request" with service token for operations to AGOL (query, delete, add, update featureLayer) before using "arcgis.gis" module. The gis object cannot be save to json, but a token can. But in this way, I need to go back to my old and a little more complicated code again.

Anyone have a better ideal!?

Ming