ArcGIS server10.1发布地图服务程序(Python),在自己机器上发布成功,别人机器上发布失败

如题,A机器装了ArcGIS Server10.1,Desktop10.1 ,Engine10.1,B机器上装了Desktop10.1,程序在A机器上成功发布,移植到B机器上(连接A机器的ip)发布失败,如图1和图2(附件中图片顺序有误-。-),同样数据在B机器上用ArcMap发布是成功的,如图3和图4。(附件中图片顺序有误-。-)发布代码如下所示:求大神帮忙分析原因!
# Demonstrates how to publish a service from a JSON definition file
# An MSD file is required, which is made from the MXD in this script

# For Http calls
import httplib, urllib, json, arcpy, os

# For system tools
import sys

# For reading passwords without echoing
import getpass


# Defines the entry point into the script

def main(argv=None):
# Print some info
print
print "This tool is a sample script that publishes a service using an MXD and JSON definiton."
print

# Ask for admin/publisher user name and password
username =arcpy.GetParameterAsText(0)
password =arcpy.GetParameterAsText(1)

# Ask for other necessary information
serverName = arcpy.GetParameterAsText(2)
serverPort = arcpy.GetParameter(3)
mxdPath = arcpy.GetParameterAsText(4)
msdPath = arcpy.GetParameterAsText(5)
jsonPath =arcpy.GetParameterAsText(6)

# Analyze MXD and create MSD file
if not os.path.isfile(mxdPath):
return

if mxdPath.endswith('.mxd'):
mapErrors = analyzeMap(mxdPath)
if len(mapErrors) > 0:
print "Fix map errors before converting to mxd"
return
mxd = arcpy.mapping.MapDocument(mxdPath)
convertMap(mxd, msdPath);
del mxd
else:
print "Invalid file type submitted"
return

# Get a token
token = getToken(username, password, serverName, serverPort)
if token == "":
print "Could not generate a token with the username and password provided."
return

# Read the JSON file for the service
serviceJSON = open(jsonPath).read()

# Construct URL to create a service
# If publishing to a folder, invoke createService on the folder URL
createServiceURL = "/arcgis/admin/services/createService"

# This request needs the token, the JSON defining the service properties,
# and the response format
params = urllib.urlencode({'token': token, 'service':serviceJSON, '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", createServiceURL, params, headers)

# Read response
response = httpConn.getresponse()
if (response.status != 200):
httpConn.close()
print "Error while creating the service."
return
else:
data = response.read()
httpConn.close()

# Check that data returned is not an error object
if not assertJsonSuccess(data):
print "Error returned by operation. " + data
else:
print "Operation completed successfully!"

return

# A function to analyze a map document
def analyzeMap(mapPath):
mxd = arcpy.mapping.MapDocument(mapPath)
analysis = arcpy.mapping.AnalyzeForMSD(mxd)

vars = analysis['errors']
for ((message, code), layerlist) in vars.iteritems():
print "Errors: "
print message, " (CODE %i)" % code
print " applies to the following layers:",
for layer in layerlist:
print layer.name,
print

del mxd
return analysis['errors']

# A function to convert a map document to a map service definition (MSD)
def convertMap(mxd, msd):
arcpy.mapping.ConvertToMSD(mxd, msd, "USE_ACTIVE_VIEW", "NORMAL", "NORMAL")
del mxd, msd

# A function to generate a token given username, password and the adminURL.
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 fetching tokens from admin URL. Please check the URL and try again."
return
else:
data = response.read()
httpConn.close()

# Check that data returned is not an error object
if not assertJsonSuccess(data):
return

# Extract the token from it
token = json.loads(data)
return token['token']

# A function that checks that the input JSON object
# is not an error object.

def assertJsonSuccess(data):
obj = json.loads(data)
if 'status' in obj and obj['status'] == "error":
print "Error: JSON object returns an error. " + str(obj)
return False
else:
return True


# Script start
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
3.png 2.png 1.png 4.png
已邀请:

Nico - 90后IT女

赞同来自: 江民彬

已解决,原因是没有copy数据到服务器,应该使用生成.sddraft-->生成.sd--->上传服务定义文件的方式发布地图服务,arcpy中有相应的是否拷贝数据的参数

要回复问题请先登录注册