Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this Python POST Request returns 400 Bad Request Code?

Tags:

python

xml

I have a Python script that does a POST Request sending an xml to a link and it returns 400 Bad Request. Where do you think is the problem ? In the xml ?

import base64
import requests
import os

proxy = 'http://26:[email protected]: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) 

I would like to obtain a 200 Code in return

Thanks in advance

like image 350
SECI Avatar asked Dec 08 '25 08:12

SECI


1 Answers

Chnage:

xml = """"

To:

xml = """ 

You have four " instead of three.

like image 103
Dipen Dadhaniya Avatar answered Dec 09 '25 22:12

Dipen Dadhaniya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!