I'm using the below Portalpy code to update my secure Feature Services on ESRI Portal which have a stored password. The return on print post_url in the script is: https://somedomain.com/portal/sharing/rest/content/users/siteadmin/f43542fd62c74db6997a5d16c9eec16e/items/c3aa864f30ee4d8fbc5241134d35762c/update with a satus code of 200. The above URL is identical when I do it manually and watch it with fiddler. However the script is not changing the U/P in portal. I assume I am passing the parameters incorrectly, but am following the user docs for construction and parameters. Anyone have any suggestions?

Portal: 10.3v

import portalpy
import requests
import json

#Login Info
username = 'XXXX'
password = 'XXXX'
portal_url = 'https:/somedomain.com/portal'
portal = portalpy.Portal(portal_url, username, password)

#get token
token = portal.generate_token(username, password, expiration=60)

#set new username
new_username = 'newu'
new_password = 'newp'

payload = {'serviceUsername':new_username, 'servicePassword':new_password}

#print  portal.get_folder_id('siteadmin')

#Search for layers
search = portal.search('Feature Service')

for i in search:
        a = i['url'].split('/')
        folder_id = portal.get_folder_id('siteadmin', a[9])
        post_url = portal.resturl + 'content/users/siteadmin/' + folder_id + '/items/' + i['id'] + '/update'
        print post_url
        post = requests.post(post_url, data=payload)
        print post.status_code
    except Exception:

You Need to pass the token in the payload. It should have been

payload = {'serviceUsername':new_username, 'servicePassword':new_password, 'token': token}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.