<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Print WebMap ArcGIS Online in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1131557#M6974</link>
    <description>&lt;P&gt;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:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for lyr in wm.layers:
    lyr['layerDefinition']['token'] = gis._conn.token&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jan 2022 12:24:57 GMT</pubDate>
    <dc:creator>AdminGIS2</dc:creator>
    <dc:date>2022-01-07T12:24:57Z</dc:date>
    <item>
      <title>Print WebMap ArcGIS Online</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1131264#M6972</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Error message in Jupyter Notebook&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;                                 Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[81]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;7&lt;/SPAN&gt;:     url = wm.print(file_format=&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;PNG32&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;,extent=ext)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\_types.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;print&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;2165&lt;/SPAN&gt;:  layout_template=layout_template,

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\_utils.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;export_map&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;99&lt;/SPAN&gt;:    gis, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;Export Web Map Task&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;, kwargs, param_db, return_values, _use_async, url

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geoprocessing\_support.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;_execute_gp_tool&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;513&lt;/SPAN&gt;:   resp = gptool._con.post(exec_url, gp_params)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;post&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1079&lt;/SPAN&gt;:  force_bytes=kwargs.pop(&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;force_bytes&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;, &lt;SPAN class=""&gt;False&lt;/SPAN&gt;),

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;_handle_response&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;625&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;self&lt;/SPAN&gt;._handle_json_error(data[&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;error&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;], errorcode)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;_handle_json_error&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;648&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; &lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;(errormessage)

&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: Invalid Token
(Error Code: 498)
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Error in a standalone Python script:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;Exception has occurred: Exception&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;Invalid Token (Error Code: 498)&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;During handling of the above exception, another exception occurred: File "&lt;A target="_blank"&gt;D:\OneDrive&lt;/A&gt; - Trans Adriatic Pipeline AG\Scripts\Python\JourneyManagementPlan\calculate_route.py", line 139, in print_webmap url = wm.print(file_format="PNG32",extent=ext,layout_template="MAP_ONLY") File "&lt;A target="_blank"&gt;D:\OneDrive&lt;/A&gt; - Trans Adriatic Pipeline AG\Scripts\Python\JourneyManagementPlan\calculate_route.py", line 167, in main print_webmap(ext) File "&lt;A target="_blank"&gt;D:\OneDrive&lt;/A&gt; - Trans Adriatic Pipeline AG\Scripts\Python\JourneyManagementPlan\calculate_route.py", line 170, in &amp;lt;module&amp;gt; main()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the relevant code snippet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;def&lt;/SPAN&gt; &lt;SPAN&gt;print_webmap&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ext&lt;/SPAN&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;wm_item&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;gis&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;content&lt;/SPAN&gt;&lt;SPAN&gt;.get(&lt;/SPAN&gt;&lt;SPAN&gt;WM_ITEM_ID&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; wm = &lt;/SPAN&gt;&lt;SPAN&gt;WebMap&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;wm_item&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;url = wm.print(&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;file_format="PNG32",extent=ext,layout_template="MAP_ONLY")&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;with&lt;/SPAN&gt;&lt;SPAN&gt; requests.get(url) &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; resp:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;with&lt;/SPAN&gt; &lt;SPAN&gt;open&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'./output_file.png'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'wb'&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; file_handle:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; file_handle.write(resp.content)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sr&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;SpatialReference&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;4326&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;x_start&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;24.38&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;y_start&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;40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lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;x_end&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"ymax"&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;y_end&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;print_webmap&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ext&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 06 Jan 2022 16:59:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1131264#M6972</guid>
      <dc:creator>MarcHoogerwerf_TAP</dc:creator>
      <dc:date>2022-01-06T16:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Print WebMap ArcGIS Online</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1131557#M6974</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for lyr in wm.layers:
    lyr['layerDefinition']['token'] = gis._conn.token&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 12:24:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1131557#M6974</guid>
      <dc:creator>AdminGIS2</dc:creator>
      <dc:date>2022-01-07T12:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Print WebMap ArcGIS Online</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1131645#M6977</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Turned out that the web map contained one layer that used stored credentials....&lt;/P&gt;&lt;P&gt;As the layer was not required I removed that layer before printing the webmap.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 17:02:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1131645#M6977</guid>
      <dc:creator>MarcHoogerwerf_TAP</dc:creator>
      <dc:date>2022-01-07T17:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Print WebMap ArcGIS Online</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1316202#M8915</link>
      <description>&lt;P&gt;Tried but still getting same error of invalid token.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 20:49:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/print-webmap-arcgis-online/m-p/1316202#M8915</guid>
      <dc:creator>Aymen_Farhat</dc:creator>
      <dc:date>2023-08-07T20:49:48Z</dc:date>
    </item>
  </channel>
</rss>

