Compiling Python scripts using ArcGIS Server administrator API (1)

Source: Internet
Author: User

ArcGIS 10.1 for server contains an administrator API that can be used to write scripts for common server operations. By writing scripts for server management, You can automatically execute various common tasks at the scheduled time. It also reduces the possibility of making mistakes when performing complex or repetitive tasks.

Using the Administrator API, you can call various management tasks supported by ArcGIS Server. In fact, all management tools attached to ArcGIS (including ArcGIS for desktop and ArcGIS Server Manager) can use this API.

The Administrator API uses a restful architecture and can be used in any language that can call web services (such as Python, Java, JavaScript, powershell, C #, Ruby, Scala, Perl, and other languages).

You can use the Administrator API to program many server management tasks, for example:

  • Create a site after installing ArcGIS Server silently
  • Send you an email when the service is unavailable
  • Add Service
  • Edit service attributes (such as the maximum number of instances)
  • Grant and revoke user permissions on services
  • Stop and start the service
  • Query logs and create a usage report based on logs

Server Admin address: http: // myserver: 6080/ArcGIS/admin

Whenever you log on to the manager or Administrator directory, you must provide the user name and password of the account with the permissions of ArcGIS Server Management or publisher. The same concept applies when writing scripts. The name and password must be submitted to the server programmatically. The server returns a token (a special string) to prove to the server that you have the permission to perform certain types of operations. Any web service request to the server must contain this token.

The token will not always be valid; it has a timeout design to prevent malicious users from stealing and using it permanently. Each time a script is run (but not every request), a new token must be requested.

You can use the following Python function to request the token. The server name, port number, user name, and password are provided as parameters.

Request management token from ArcGIS Server

Def gettoken (username, password, servername, SERVERPORT ):
# Token URL is typically

Http: // server [: Port]/ArcGIS/admin/generatetoken

Tokenurl = "/ArcGIS/admin/generatetoken"

# URL-encode the token parameters :-
Params = urllib. urlencode ({'username': username, 'Password': Password, 'client': 'requestip', 'F': 'json '})

Headers = {"Content-Type": "application/X-WWW-form-urlencoded", "accept": "text/plain "}

# Connect to URL and post Parameters
Httpconn = httplib. httpconnection (servername, SERVERPORT)
Httpconn. Request ("Post", tokenurl, Params, headers)

# Read response
Response = httpconn. getresponse ()
If (response. status! = 200 ):
Httpconn. Close ()
Print "error while fetch tokens from admin URL. Please check the URL and try again ."
Return
Else:
Data = response. Read ()
Httpconn. Close ()

# Extract the token from it
Token = JSON. Loads (data)
Return Token ['Token']

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.