Hi I'm trying to print/export a WebMap from ArcGIS Online through the API for Python but getting an invalid token error. I have no issue interacting with the WebMap itself, so the token should be valid. I can display the WebMap in a Jupyter Notebook, update the WebMap in a standalone script, etc.
It's only when the print line, indicated in bold below gets executed, processing starts, takes a while and then returns with the error message invalid token.
Error message in Jupyter Notebook
--------------------------------------------------------------------------- Exception Traceback (most recent call last) In [81]: Line 7: url = wm.print(file_format="PNG32",extent=ext) File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\_types.py, in print: Line 2165: layout_template=layout_template, File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\_utils.py, in export_map: Line 99: gis, "Export Web Map Task", kwargs, param_db, return_values, _use_async, url File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geoprocessing\_support.py, in _execute_gp_tool: Line 513: resp = gptool._con.post(exec_url, gp_params) File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in post: Line 1079: force_bytes=kwargs.pop("force_bytes", False), File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_response: Line 625: self._handle_json_error(data["error"], errorcode) File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_json_error: Line 648: raise Exception(errormessage) Exception: Invalid Token (Error Code: 498) ---------------------------------------------------------------------------
Error in a standalone Python script:
Here is the relevant code snippet.
def print_webmap(ext😞
Solved! Go to Solution.
Thanks
Turned out that the web map contained one layer that used stored credentials....
As the layer was not required I removed that layer before printing the webmap.
If the webmap contains secured services you might have to supply a valid token to the layer definition as well in order for the print function to work. You could try something like this:
for lyr in wm.layers:
lyr['layerDefinition']['token'] = gis._conn.token
Tried but still getting same error of invalid token.
Thanks
Turned out that the web map contained one layer that used stored credentials....
As the layer was not required I removed that layer before printing the webmap.