Closed DShokes closed 7 years ago
Since ArcGIS Online credentials can't be defined in arcpy, I should mention that some modules of the script involve arcpy exporting pdf's of an mxd with a layer referencing a hosted service layer. The invalid token message still occurs with a module that only imports arcrest, arcresthelper, and pyodbc,
The security handler is designed to refresh the token when it expires. Can you build a repo case and share it with us?
File "..\env\lib\site-packages\arcrest\agol\services.py", line 1774, in query raise ValueError(result)
ValueError: {u'error': {u'message': u'Invalid token.', u'code': 498, u'details': [u'Invalid token.']}}
Occurs after I run the following for 2 hours as a stand alone script.
def testtoken(fl):
#run this until the expiration date occurs
while True:
print('Current Time: ', datetime.datetime.now())
print('Token Obtained: ', fl.securityHandler.tokenObtainedDate)
print('token Expires: ',fl.securityHandler.tokenExperationDate)
print('Feature Count: ', fl.query(returnCountOnly=True))
return
def main():
fl = gis_FeatureLayer()
testtoken(fl)
return
if __name__ == '__main__':
main()
gis_FeatureLayer() returns a FeatureLayer Object that is created the same way as this sample
ArcRest or ArcRestHelper
Both
Version or date of download
3.5.5
Bug or Enhancement
Token should be renew if necessary before a function requiring it is executed.
Repo Steps or Enhancement details
I have an ongoing script that queries a hosted layer regularly to perform work locally. At a certain point, the token for the FeatureLayer instance expires and the script comes to a crashing stop.
I have tried to include this function in my loop:
However, I still seem to get an invalid token error every few hours. Is it possible for the FeatureLayer class to handle its own token renewal before executing functions like query? I can't seem to account for every http call with a token across all my modules. Thanks.