我是python的新手。我需要通过url获取数据。数据基于有效载荷中的唯一编号。我似乎找不到找到在有效负载中的“ CUSTNO”中初始化变量并对其进行迭代的方法。重复它。 (我已经删除了一些有效载荷数据)
url = 'url'
payload = "<CHANNELID></CHANNELID>\r\n </FCDB_HEADER>\r\n <FCDB_BODY>\r\n <CUSTOMER>\r\n " \
"<CUSTNO>123456789</CUSTNO>\r\n </CUSTOMER>\r\n"
response = requests.request("POST", url, data=payload, headers=headers)
xml_response = response.text
print(xml_response)
答案 0 :(得分:0)
您的问题确实不清楚! 也许您的有效载荷格式是错误的。您正在使用哪个版本的Python?
尝试一下:
payload = '''<CHANNELID></CHANNELID>\r\n </FCDB_HEADER>\r\n <FCDB_BODY>\r\n <CUSTOMER>\r\n \
<CUSTNO>123456789</CUSTNO>\r\n </CUSTOMER>\r\n'''
答案 1 :(得分:0)
下面(假设您要更改客户编号)
url = 'url'
customer_no = 4562
payload = "<CHANNELID></CHANNELID>\r\n </FCDB_HEADER>\r\n <FCDB_BODY>\r\n <CUSTOMER>\r\n " \
"<CUSTNO>{}</CUSTNO>\r\n </CUSTOMER>\r\n"
response = requests.request("POST", url, data=payload.format(customer_no), headers=headers)
xml_response = response.text
print(xml_response)