简体   繁体   中英

post request with xml as data is giving error 415

import requests

#data is set to true inside xml tag enable, Not sure why it is showing just true while posting the question
data = '<enable>true</enable>'


response = requests.put('http://10.59.131.51:80/rest/config/running/dot1x/enable', data=data, auth=('admin', 'password'))

print response

response = requests.put('http://10.59.131.51:80/rest/config/running/dot1x/enable', data=data, auth=('admin', 'password'),headers={'Content-type':'application/xml'})

print response

the error meaning that the content type sent and the data are differents kind of. The HTTP Code 415 says Unsupported Media Type .

Why happened that? Is because in your request you are sending content type = application/xml and the data=True, a boolean type. Only change True by an valid XML (according to yours requeriments).

Acoording to documentation ( http://docs.python-requests.org/en/master/user/quickstart/ ), the data argument is the place where you configure the document to send to the server, in this case need be an XML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM