<?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: Disable Schema locks on multiple services in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/disable-schema-locks-on-multiple-services/m-p/1121362#M63107</link>
    <description>&lt;P&gt;I would strongly suggest using the ArcGIS Python API for this. Using the &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#service" target="_blank"&gt;arcgis.gis.server module&lt;/A&gt;, you can update the service JSON. Combined with a few other classes in the same module, you can easily search for or list multiple services, then update their JSON iteratively.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Nov 2021 18:23:24 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2021-11-30T18:23:24Z</dc:date>
    <item>
      <title>Disable Schema locks on multiple services</title>
      <link>https://community.esri.com/t5/python-questions/disable-schema-locks-on-multiple-services/m-p/1121342#M63105</link>
      <description>&lt;P&gt;I need to disable the schema locks from 30 map services and can do it through Server one by one but that would take a long time. I have the following but nothing happens the services don't get schema locks don't get disabled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import urllib, json
import urllib.request
import requests


def main():

    portalURL = r'***'
    username = '***'
    password = '***'
    new_token = generateToken(username, password, portalURL)

    # edit a service
    serviceURL = '***/arcgis/admin/***.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
    '''&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 17:59:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/disable-schema-locks-on-multiple-services/m-p/1121342#M63105</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2021-11-30T17:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Disable Schema locks on multiple services</title>
      <link>https://community.esri.com/t5/python-questions/disable-schema-locks-on-multiple-services/m-p/1121362#M63107</link>
      <description>&lt;P&gt;I would strongly suggest using the ArcGIS Python API for this. Using the &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#service" target="_blank"&gt;arcgis.gis.server module&lt;/A&gt;, you can update the service JSON. Combined with a few other classes in the same module, you can easily search for or list multiple services, then update their JSON iteratively.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 18:23:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/disable-schema-locks-on-multiple-services/m-p/1121362#M63107</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-11-30T18:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Disable Schema locks on multiple services</title>
      <link>https://community.esri.com/t5/python-questions/disable-schema-locks-on-multiple-services/m-p/1122948#M63152</link>
      <description>&lt;P&gt;Thank you for the suggestion but I would like to stay with python. Python API would be a total different world for me. Do you know of an example of what I am wanting to do with Python API ?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 15:28:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/disable-schema-locks-on-multiple-services/m-p/1122948#M63152</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2021-12-06T15:28:58Z</dc:date>
    </item>
  </channel>
</rss>

