import requests
import json
host = '192.168.221.111'
def getToken(session, user, password):
url = f"http://{host}:8090/iserver/services/security/tokens.rjson"
data = {
"userName": user,
"password": password,
"clientType": "NONE",
"expiration": 10
}
headers = {"Content-Type": "application/json"}
response = session.post(url, data=json.dumps(data), headers=headers)
if response.status_code == 200:
token = response.text
# 登录成功后的操作
print("登录成功")
# 可以在这里添加其他操作
else:
print("登录失败")
# 可以在这里处理登录失败的情况
return token
def getWorkSpace(session, token, host):
url = 'http://' + host + ':8090/iserver/manager/workspaces.rjson?token=' + token
data = {"workspaceConnectionInfo":"/home/fanqy/tmp5.smwu","servicesTypes":["RESTTRANSPORTATIONANALYST"],"isMultiInstance":'false',"instanceCount":"","transportationAnalystSetting":{"weightFieldInfos":[{"backWeightField":"SmLength","forwardWeightField":"SmLength","name":"SmLength"}],"workspaceConnectString":"/home/fanqy/tmp5.smwu","datasourceName":"my_datasource","datasetName":"result","nodeIDField":"SmNodeID","edgeIDField":"SmEdgeID","fromNodeIDField":"SmFNode","toNodeIDField":"SmTNode","initFacilityAnalyst":'false',"directionField":""}}
#发送post请求
headers = {}
response = session.post(url, data=data, headers=headers)
if response.status_code == 200:
created_services = response.json()
print(created_services)
# for service_info in created_services:
# print(f"Service Type: {service_info['serviceType']}")
# print(f"Service Address: {service_info['serviceAddress']}")
else:
print(f"Failed to create services. Status code: {response.text}")
代码如上面所示,报错信息为:登录成功
P4Uq7AAbNao7n55CELiuWOHa24NGVKacDFg2goZfNdC5Nh4-GlURKG1FFm5yK04am4_wiwY_FQMwudVmz8uMLw..
Failed to create services. Status code: {
"succeed": false,
"error": {
"code": 500,
"errorMsg": "class java.lang.String cannot be cast to class com.supermap.services.rest.management.PublishServiceParameter (java.lang.String is in module java.base of loader 'bootstrap'; com.supermap.services.rest.management.PublishServiceParameter is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @9fec931)"
}
}
Process finished with exit code 0
请问应该怎么解决?