<?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 How to generate token for ArcGIS Online/Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68409#M5583</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to consume hosted features from ArcGIS Online into a local file geodatabase.&amp;nbsp; I am consistently receving a 498 error.&amp;nbsp; I am generating a token but when passing into ArcGIS server it is invalid.&amp;nbsp; A couple of questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a.) Do I need to use my organization url, i.e. myorg.maps.arcgis.com for my referrer?&lt;/P&gt;&lt;P&gt;b.) When I am creating a replica; should this data be hosted in arcgis.com?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am making some changes to the script&amp;nbsp; linked below which I found on github that uses urllib2, it doesn't work and isn't as elegant as the Requests.&amp;nbsp; And for my purposes I do not need to add attachments to the database, just consume a table locally.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://gist.github.com/oevans/6992139" title="https://gist.github.com/oevans/6992139" rel="nofollow noopener noreferrer" target="_blank"&gt;Python script to pull hosted features with attachments into a local file geodatabase. See ReadMe below.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are my script and results&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="background-color: #ffe4ff;"&gt;url&lt;/SPAN&gt; &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://www.arcgis.com/sharing/generateToken" rel="nofollow noopener noreferrer" target="_blank"&gt;https://www.arcgis.com/sharing/generateToken&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;
&lt;/SPAN&gt;payload&amp;nbsp; &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;{&lt;SPAN style="color: #dd1144;"&gt;'username' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'myUser,
&lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'password' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'myPass!'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'referer' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'www.arcgis.com'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'f' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'json' &lt;/SPAN&gt;}

r &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;requests.post(&lt;SPAN style="background-color: #e4e4ff;"&gt;url&lt;/SPAN&gt;, data&lt;SPAN style="font-weight: bold;"&gt;=&lt;/SPAN&gt;payload)
token &lt;SPAN style="font-weight: bold;"&gt;=&lt;/SPAN&gt;json.loads (r.text)

aToken &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;token[&lt;SPAN style="color: #dd1144;"&gt;'token'&lt;/SPAN&gt;]

&lt;SPAN style="font-weight: bold;"&gt;print &lt;/SPAN&gt;aToken

&lt;SPAN style="color: #999988; font-style: italic;"&gt;# Create Replica ###
&lt;/SPAN&gt;&lt;SPAN style="color: #999988; font-style: italic;"&gt;# Update service url HERE ###
&lt;/SPAN&gt;url2 &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://myIP:6080/arcgis/rest/services/FeatureMapService/FeatureServer/CreateReplica" rel="nofollow noopener noreferrer" target="_blank"&gt;http://myIP:6080/arcgis/rest/services/FeatureMapService/FeatureServer/CreateReplica&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #999988; font-style: italic;"&gt;# #
&lt;/SPAN&gt;payload2 &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;{&lt;SPAN style="color: #dd1144;"&gt;'f' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'json'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'layers' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'1'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'returnAttachments' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'false'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'token' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;token }


r2 &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;requests.post(url2, data&lt;SPAN style="font-weight: bold;"&gt;=&lt;/SPAN&gt;payload2)
repLoad &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;json.loads (r2.text)


&lt;SPAN style="font-weight: bold;"&gt;print &lt;/SPAN&gt;repLoad
&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;C:\Python27\ArcGIS10.2\python.exe C:/Users/GIS/Documents/ArcGIS/timequery.py
lOg8435-zLN8aeWknNveul8EzYlmbKb2h5GXVHCazEEbs0VgvyKH-0rr-iZ3RNwN_HP0BfykxtuzgZaw_Bm8LMZoOoJ9KtydsLze2mEX5qcFKBKltW_goPIH9w43jvgtCqHGAbotdyGMTAZZ217QEVTNqnW74rgBtjf1eB7XFMUb1miuJbU2YhPDnpbQB1S-9alNOrp6loXtBzJFEN-oAA..
{u'error': {u'message': u'Invalid Token', u'code': 498, u'details': []}}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:37:26 GMT</pubDate>
    <dc:creator>GeoffreyWest</dc:creator>
    <dc:date>2021-12-10T22:37:26Z</dc:date>
    <item>
      <title>How to generate token for ArcGIS Online/Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68409#M5583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to consume hosted features from ArcGIS Online into a local file geodatabase.&amp;nbsp; I am consistently receving a 498 error.&amp;nbsp; I am generating a token but when passing into ArcGIS server it is invalid.&amp;nbsp; A couple of questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a.) Do I need to use my organization url, i.e. myorg.maps.arcgis.com for my referrer?&lt;/P&gt;&lt;P&gt;b.) When I am creating a replica; should this data be hosted in arcgis.com?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am making some changes to the script&amp;nbsp; linked below which I found on github that uses urllib2, it doesn't work and isn't as elegant as the Requests.&amp;nbsp; And for my purposes I do not need to add attachments to the database, just consume a table locally.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://gist.github.com/oevans/6992139" title="https://gist.github.com/oevans/6992139" rel="nofollow noopener noreferrer" target="_blank"&gt;Python script to pull hosted features with attachments into a local file geodatabase. See ReadMe below.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are my script and results&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="background-color: #ffe4ff;"&gt;url&lt;/SPAN&gt; &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://www.arcgis.com/sharing/generateToken" rel="nofollow noopener noreferrer" target="_blank"&gt;https://www.arcgis.com/sharing/generateToken&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;
&lt;/SPAN&gt;payload&amp;nbsp; &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;{&lt;SPAN style="color: #dd1144;"&gt;'username' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'myUser,
&lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'password' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'myPass!'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'referer' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'www.arcgis.com'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'f' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'json' &lt;/SPAN&gt;}

r &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;requests.post(&lt;SPAN style="background-color: #e4e4ff;"&gt;url&lt;/SPAN&gt;, data&lt;SPAN style="font-weight: bold;"&gt;=&lt;/SPAN&gt;payload)
token &lt;SPAN style="font-weight: bold;"&gt;=&lt;/SPAN&gt;json.loads (r.text)

aToken &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;token[&lt;SPAN style="color: #dd1144;"&gt;'token'&lt;/SPAN&gt;]

&lt;SPAN style="font-weight: bold;"&gt;print &lt;/SPAN&gt;aToken

&lt;SPAN style="color: #999988; font-style: italic;"&gt;# Create Replica ###
&lt;/SPAN&gt;&lt;SPAN style="color: #999988; font-style: italic;"&gt;# Update service url HERE ###
&lt;/SPAN&gt;url2 &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://myIP:6080/arcgis/rest/services/FeatureMapService/FeatureServer/CreateReplica" rel="nofollow noopener noreferrer" target="_blank"&gt;http://myIP:6080/arcgis/rest/services/FeatureMapService/FeatureServer/CreateReplica&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #999988; font-style: italic;"&gt;# #
&lt;/SPAN&gt;payload2 &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;{&lt;SPAN style="color: #dd1144;"&gt;'f' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'json'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'layers' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'1'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'returnAttachments' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #dd1144;"&gt;'false'&lt;/SPAN&gt;,
&lt;SPAN style="color: #dd1144;"&gt;'token' &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold;"&gt;: &lt;/SPAN&gt;token }


r2 &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;requests.post(url2, data&lt;SPAN style="font-weight: bold;"&gt;=&lt;/SPAN&gt;payload2)
repLoad &lt;SPAN style="font-weight: bold;"&gt;= &lt;/SPAN&gt;json.loads (r2.text)


&lt;SPAN style="font-weight: bold;"&gt;print &lt;/SPAN&gt;repLoad
&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;C:\Python27\ArcGIS10.2\python.exe C:/Users/GIS/Documents/ArcGIS/timequery.py
lOg8435-zLN8aeWknNveul8EzYlmbKb2h5GXVHCazEEbs0VgvyKH-0rr-iZ3RNwN_HP0BfykxtuzgZaw_Bm8LMZoOoJ9KtydsLze2mEX5qcFKBKltW_goPIH9w43jvgtCqHGAbotdyGMTAZZ217QEVTNqnW74rgBtjf1eB7XFMUb1miuJbU2YhPDnpbQB1S-9alNOrp6loXtBzJFEN-oAA..
{u'error': {u'message': u'Invalid Token', u'code': 498, u'details': []}}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:37:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68409#M5583</guid>
      <dc:creator>GeoffreyWest</dc:creator>
      <dc:date>2021-12-10T22:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate token for ArcGIS Online/Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68410#M5584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't done this, but maybe you can find something useful in this Esri Blog post about &lt;A href="https://github.com/Esri/ArcREST"&gt;ARCREST&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.esri.com/esri/arcgis/2015/03/24/spatialize-your-water-utility-data-with-arcgis/" title="http://blogs.esri.com/esri/arcgis/2015/03/24/spatialize-your-water-utility-data-with-arcgis/"&gt;Spatialize Your Water Utility Data with ArcGIS | ArcGIS Blog&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2015 21:52:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68410#M5584</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-04-23T21:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate token for ArcGIS Online/Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68411#M5585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How is your arcgis servers security configured?&amp;nbsp; Are you federated with your arcgis.com solution?&amp;nbsp; What is your user and role store?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Apr 2015 13:08:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68411#M5585</guid>
      <dc:creator>PF1</dc:creator>
      <dc:date>2015-04-25T13:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate token for ArcGIS Online/Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68412#M5586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am an admin user, this solution does not seem very viable as the table has to be hosted on ArcGIS Server, I would like to host a table in ArcGIS Online and consume it to a&amp;nbsp; local file geodatabase with python.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 13:56:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68412#M5586</guid>
      <dc:creator>GeoffreyWest</dc:creator>
      <dc:date>2015-04-28T13:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate token for ArcGIS Online/Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68413#M5587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Geoffrey,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you are trying to use your ArcGIS Online (AGOL) token to authorize your access to your ArcGIS Server (AGS).&amp;nbsp; I think you need to have your AGS federated with AGOL in order for this to work.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If AGS is not federated with AGOL, then you need to acquire an &lt;A href="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Generate_Token/02r3000000ts000000/"&gt;AGS token&lt;/A&gt; and use that for access to web-services hosted with AGS.&amp;nbsp; This also assumes your AGS 'site' is setup to use ArcGIS Tokens for its authentication tier which is the default settings when deployed.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have switched to a 'web-tier' authentication scheme, then you do not require tokens any more but rather use the authentication mechanisms that your web-adaptor deployment supports such as: &lt;/P&gt;&lt;UL&gt;&lt;LI&gt;HTTP Basic&lt;/LI&gt;&lt;LI&gt;HTTP Digest&lt;/LI&gt;&lt;LI&gt;Integrated Windows Authentication (IWA) Using Kerberos or NTLM&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at this thread and see if it helps shed some light: &lt;A href="https://community.esri.com/message/479803"&gt;Re: Federating an ArcGIS Server site with your portal&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 15:12:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-generate-token-for-arcgis-online-python/m-p/68413#M5587</guid>
      <dc:creator>PF1</dc:creator>
      <dc:date>2015-04-28T15:12:13Z</dc:date>
    </item>
  </channel>
</rss>

