I am using a Python script to change roles of users, etc also creating roles is working.
but wenn i go to set-privileges of the role i get an error
{u'error': {u'messageCode': u'ORG_1064', u'message': u"Invalid JSON in 'privileges' parameter.", u'code': 400, u'details': []}}
maybe it has to do with, that i do an URLENCODE of the post-data before sending to the API.
This worked for the other requests, but not for the set-privileges request, whre i have to send a list...
further i try to send the json directly to the api or via JSON.DUMPS, but i did not get it working yet.
do you have an working example how i can send post data to set privileges in python?
on the machine i have only arcgis portal and arcgis server. i dont have libraries of other arcgis-software
Solved! Go to Solution.
Now it works ... Let me say, that is not intuitive!
So what I send to the api, what is working is:
{ … 'privileges': {'privileges': [ … ] } … }
I am sure this is not a bug, it is a feature 😉
this is not working:
r = requests.post(url, data=data,headers=headers,verify=False)
r = requests.post(url, data=json.dumps(data),headers=headers,verify=False)
r = requests.post(url, json=data,headers=headers,verify=False)
everytime i get an error 403
You can try this method, example to generate token :
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)
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 : https://developers.arcgis.com/rest/
Your error seems to indicate a problem with the JSON.
Maybe the easyest way to do this it's to use ArcGIS API for Python to manage user : https://developers.arcgis.com/python/guide/accessing-and-managing-users/
This is a question - NOT a solution.
This is an python3 example, right?
It is not working here: response = urllib.request.urlopen(URL, data=postdata, context=gcontext)
AttributeError: 'module' object has no attribute 'request'
Yes it's a python 3 example.
I'm not sure of the reason but it depends of the import of the module. Try to add module "urllib.request" in import.
Maybe my example has this import elsewhere and I don't copy it here. I try it with Jupyter Notebook with ArcGIS PRO.
Now it works ... Let me say, that is not intuitive!
So what I send to the api, what is working is:
{ … 'privileges': {'privileges': [ … ] } … }
I am sure this is not a bug, it is a feature 😉