运行代码:
register_url = 'http://XXX.XX.X.XX:9090/capi/auth-company/auth/registerCompany/9999'
register_data = {"qylx": ["14", "15"], "tyshxydm": "999909098989090091", "qymc": "暖暖03", "zzjgdm": "9099909001",
"fddbr": "欧阳南岸", "qyzyyw": "10", "qylsqx": "", "qyszqy": "", "qytxdz": "满洲里网红街",
"qylxr": "欧阳南岸", "sslsxzglbm": "LS001036", "sslsxzglbmmc": "满洲里市粮食和物资储备局",
"qylsqxname": "满洲里市粮食和物资储备局", "jyfwVal": ["粮油收储企业"], "shixian": ["153100"],
"qyszqybh": "153100", "qyzt": 2, "bgdh": "18889899123", "shi": "153100", "xian": "",
"orgainzeDTO": {"parentCode": "LS001036", "orgName": "暖暖"},
"tzQylxVOList": [{"qylxmc": "加工", "qylxbh": "14"}, {"qylxmc": "应急", "qylxbh": "15"}],
"userDTO": {"userMobile": "18889899123", "userType": "2", "imgsrc": "", "titlesrc": "",
"userLoginName": "ouyangnanan", "userPassword": "Lscbj@12345",
"userPasswordAgain": "Lscbj@12345", "userName": "欧阳南岸"}, "msgCode": "9999",
"jyfw": "[\"粮油收储企业\"]"}
res = requests.post(register_url,register_data, headers={'content-type': 'application/json;charset=UTF-8'})
# print('text解析的结果是:',res.text)
print('json解析的结果是:', res.json())
运行过程中报错如下:
json解析的结果是: {'timestamp': '2023-05-31T15:58:42.943+0800', 'status': 400, 'error': 'Bad Request', 'message': "JSON parse error: Unrecognized token 'qylx': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'qylx': was expecting ('true', 'false' or 'null')\n at [Source: (PushbackInputStream); line: 1, column: 6]", 'path': '/auth/registerCompany/9999'}
解决方法:调整post请求的中的参数
register_url = 'http://XXX.XX.X.XX:9090/capi/auth-company/auth/registerCompany/9999'
register_data = {"qylx": ["14", "15"], "tyshxydm": "999909098989090091", "qymc": "暖暖03", "zzjgdm": "9099909001",
"fddbr": "欧阳南岸", "qyzyyw": "10", "qylsqx": "", "qyszqy": "", "qytxdz": "满洲里网红街",
"qylxr": "欧阳南岸", "sslsxzglbm": "LS001036", "sslsxzglbmmc": "满洲里市粮食和物资储备局",
"qylsqxname": "满洲里市粮食和物资储备局", "jyfwVal": ["粮油收储企业"], "shixian": ["153100"],
"qyszqybh": "153100", "qyzt": 2, "bgdh": "18889899123", "shi": "153100", "xian": "",
"orgainzeDTO": {"parentCode": "LS001036", "orgName": "暖暖"},
"tzQylxVOList": [{"qylxmc": "加工", "qylxbh": "14"}, {"qylxmc": "应急", "qylxbh": "15"}],
"userDTO": {"userMobile": "18889899123", "userType": "2", "imgsrc": "", "titlesrc": "",
"userLoginName": "ouyangnanan", "userPassword": "Lscbj@12345",
"userPasswordAgain": "Lscbj@12345", "userName": "欧阳南岸"}, "msgCode": "9999",
"jyfw": "[\"粮油收储企业\"]"}
res = requests.post(register_url, data=json.dumps(register_data), headers={'content-type': 'application/json;charset=UTF-8'})
# print('text解析的结果是:',res.text)
print('json解析的结果是:', res.json())