为什么此Python POST请求返回400错误的请求代码?

时间:2019-10-08 08:01:49

标签: python xml

我有一个Python脚本,该脚本执行POST请求,将xml发送到链接,并返回400 Bad Request。您认为问题出在哪里?在xml中?

import base64
import requests
import os

proxy = 'http://26:Do7@proxy.f.c:8080'

os.environ['http_proxy'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['HTTPS_PROXY'] = proxy

with open("exemplu.pdf","rb") as pdf_file:
encoded_string = base64.b64encode(pdf_file.read())
b64 = encoded_string
#print(b64)

xml = """"<header xmlns="mfp:anaf:dgti:spv:reqStareMesaj:v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<listaMesaje index_incarcare="390"></listaMesaje>
</header>"""


headers = {'Content-Type':'application/xml','Authorization':'Bearer     f73e'}
x = requests.post('https://api.anaf.ro/SPVWS2/rest/stareMesaj',data=xml,headers=headers)
print(x.status_code)
print(x.content)
#print(xml) 

我想获得200码作为回报

预先感谢

2 个答案:

答案 0 :(得分:5)

Chnage:

xml = """"

收件人:

xml = """ 

您有四个"而不是三个。

答案 1 :(得分:0)

打印

xml = """"<header xmlns="mfp:anaf:dgti:spv:reqStareMesaj:v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<listaMesaje index_incarcare="390"></listaMesaje>
</header>"""

print(xml)

(此处忽略错误的语法着色)会导致

"<header xmlns="mfp:anaf:dgti:spv:reqStareMesaj:v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<listaMesaje index_incarcare="390"></listaMesaje>
</header>

wich是无效的xml。

相关问题