<?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: Looking for an example Python https-post script which communicates with portal-api in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1095687#M31053</link>
    <description>&lt;P&gt;This is a question - NOT a solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an python3 example, right?&lt;/P&gt;&lt;P&gt;It is not working here: response = urllib.request.urlopen(URL, data=postdata, context=gcontext)&lt;BR /&gt;AttributeError: 'module' object has no attribute 'request'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Sep 2021 07:08:15 GMT</pubDate>
    <dc:creator>MichaelNüßlein</dc:creator>
    <dc:date>2021-09-06T07:08:15Z</dc:date>
    <item>
      <title>Looking for an example Python https-post script which communicates with portal-api</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1090733#M30972</link>
      <description>&lt;P&gt;I am using a Python script to change roles of users, etc also creating roles is working.&lt;/P&gt;&lt;P&gt;but wenn i go to set-privileges of the role i get an error&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;{u'error': {u'messageCode': u'ORG_1064', u'message': u"Invalid JSON in 'privileges' parameter.", u'code': 400, u'details': []}}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;maybe it has to do with, that i do an URLENCODE of the post-data before sending to the API.&lt;/P&gt;&lt;P&gt;This worked for the other requests, but not for the set-privileges request, whre i have to send a list...&lt;/P&gt;&lt;P&gt;further i try to send the json directly to the api or via JSON.DUMPS, but i did not get it working yet.&lt;/P&gt;&lt;P&gt;do you have an working example how i can send post data to set privileges in python?&lt;/P&gt;&lt;P&gt;on the machine i have only arcgis portal and arcgis server. i dont have libraries of other arcgis-software&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 09:05:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1090733#M30972</guid>
      <dc:creator>KlausWieland</dc:creator>
      <dc:date>2021-08-20T09:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for an example Python https-post script which communicates with portal-api</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1090737#M30973</link>
      <description>&lt;P&gt;this is not working:&lt;/P&gt;&lt;P&gt;r = requests.post(url, data=data,headers=headers,verify=False)&lt;/P&gt;&lt;P&gt;r = requests.post(url, data=json.dumps(data),headers=headers,verify=False)&lt;/P&gt;&lt;P&gt;r = requests.post(url, json=data,headers=headers,verify=False)&lt;/P&gt;&lt;P&gt;everytime i get an error 403&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 09:36:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1090737#M30973</guid>
      <dc:creator>KlausWieland</dc:creator>
      <dc:date>2021-08-20T09:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for an example Python https-post script which communicates with portal-api</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1090745#M30974</link>
      <description>&lt;P&gt;You can try this method, example to generate token :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import http, urllib.parse, json, ssl

gcontext = ssl.SSLContext()

URL = "https://xxxxxxxxxx/arcgis/admin/generateToken"

postdata = {'username': "xxxxxxxxxx", 'password': "xxxxxxxxxx", 'client': 'requestip', 'f': 'json'}
postdata = urllib.parse.urlencode(postdata).encode("utf-8")
response = urllib.request.urlopen(URL, data=postdata, context=gcontext)

data = response.read()
response.close()
tokenAGS = json.loads(data)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will just have to check that you are using the correct parameters in postdata. You can use this doc to see what parameters is used in request : &lt;A title="https://developers.arcgis.com/rest/users-groups-and-items/set-role-privileges.htm" href="https://developers.arcgis.com/rest/users-groups-and-items/set-role-privileges.htm" target="_self"&gt;https://developers.arcgis.com/rest/&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Your error seems to indicate a problem with the JSON.&lt;/P&gt;&lt;P&gt;Maybe the easyest way to do this it's to use ArcGIS API for Python to manage user : &lt;A href="https://developers.arcgis.com/python/guide/accessing-and-managing-users/" target="_self"&gt;https://developers.arcgis.com/python/guide/accessing-and-managing-users/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 10:22:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1090745#M30974</guid>
      <dc:creator>GaetanPRU</dc:creator>
      <dc:date>2021-08-20T10:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for an example Python https-post script which communicates with portal-api</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1095687#M31053</link>
      <description>&lt;P&gt;This is a question - NOT a solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an python3 example, right?&lt;/P&gt;&lt;P&gt;It is not working here: response = urllib.request.urlopen(URL, data=postdata, context=gcontext)&lt;BR /&gt;AttributeError: 'module' object has no attribute 'request'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 07:08:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1095687#M31053</guid>
      <dc:creator>MichaelNüßlein</dc:creator>
      <dc:date>2021-09-06T07:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for an example Python https-post script which communicates with portal-api</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1096645#M31082</link>
      <description>&lt;P&gt;Yes it's a python 3 example.&lt;/P&gt;&lt;P&gt;I'm not sure of the reason but it depends of the import of the module. Try to add module "urllib.request" in import.&lt;/P&gt;&lt;P&gt;Maybe my example has this import elsewhere and I don't copy it here. I try it with Jupyter Notebook with ArcGIS PRO.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 07:37:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1096645#M31082</guid>
      <dc:creator>GaetanPRU</dc:creator>
      <dc:date>2021-09-09T07:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for an example Python https-post script which communicates with portal-api</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1097268#M31094</link>
      <description>&lt;P&gt;Now it works ... Let me say, that is not intuitive!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I send to the api, what is working is:&lt;/P&gt;&lt;P&gt;{ … 'privileges': {'privileges': [ … ] } … }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am sure this is not a bug, it is a feature &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 16:37:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/looking-for-an-example-python-https-post-script/m-p/1097268#M31094</guid>
      <dc:creator>KlausWieland</dc:creator>
      <dc:date>2021-09-10T16:37:14Z</dc:date>
    </item>
  </channel>
</rss>

