# python3字符串换行,在右边加个反斜杠
body = '<?xml version="1.0" encoding = "UTF-8"?>' \
'<COM>' \
'<REQ name="上海-悠悠">' \
'<USER_ID>yoyoketang</USER_ID>' \
'<commodity_ID>123456</commodity_ID>' \
'<SESSION_ID>absbnmasbnfmasbm1213</SESSION_ID>' \
'</REQ>' \
'</COM>'
# 遇到编码报错时候,对body进行encode
r = requests.post(url, data=body.encode("utf-8"))
print(r.text)
curpath = os.path.dirname(os.path.realpath(__file__)) xmlpath = os.path.join(curpath, "body1_xml") with open(xmlpath, encoding="utf-8") as fp: body = fp.read() # 读取xml文件 print(body)