簡體   English   中英

帶有xml的發布請求作為數據給出錯誤415

[英]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

錯誤,表示發送的內容類型和數據不同。 HTTP代碼415表示不支持的媒體類型

為什么會這樣 這是因為在您的請求中,您要發送的內容類型為application / xml,而數據類型為True,這是布爾類型。 僅通過有效的XML更改True(根據您的要求)。

Acoording到文檔( http://docs.python-requests.org/en/master/user/quickstart/ ), 數據參數是你配置文件發送到服務器,在這種情況下不必是XML的地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM