Hello,
You can do it via the REST API. Most of the documentation out there is written for Python 2.7.
Here is a code in Python 3. You can add a loop to switch the serviceURL, that should do it.
import urllib, json
import urllib.request
import requests
def main():
portalURL = r''
username = ''
password = ''
new_token = generateToken(username, password, portalURL)
# edit a service
serviceURL = '<server root url>/admin/services/<service_name>.MapServer'
params = {'f': 'json', 'token': new_token}
req = urllib.request.Request(serviceURL, urllib.parse.urlencode(params).encode("utf-8"))
response = urllib.request.urlopen(req)
data = json.load(response)
data["properties"]["schemaLockingEnabled"] = "false"
# Serialize back into JSON
updatedSvcJson = json.dumps(data)
# Call the edit operation on the service. Pass in modified JSON.
editSvcURL = serviceURL + "/edit"
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
params_e = urllib.parse.urlencode({'token':new_token, 'f': 'json', 'service': updatedSvcJson})
r = requests.post(editSvcURL, params_e, headers = headers)
def generateToken(username, password, portalUrl):
'''Retrieves a token to be used with API requests.'''
parameters = urllib.parse.urlencode({'username' : username,
'password' : password,
'client' : 'referer',
'referer': portalUrl,
'expiration': 60,
'f' : 'json'}).encode("utf-8")
response = urllib.request.urlopen(portalUrl + '/sharing/rest/generateToken?',parameters).read()
try:
jsonResponse = json.loads(response)
if 'token' in jsonResponse:
return jsonResponse['token']
elif 'error' in jsonResponse:
print(jsonResponse['error']['message'])
for detail in jsonResponse['error']['details']:
print(detail)
except ValueError:
print('An unspecified error occurred.')
if __name__ == '__main__':
'''
debug
'''
main()