問題:python使用requests庫實(shí)現(xiàn) http的put get。get現(xiàn)在沒有問題,使用PUT時(shí) 需要攜帶xml的數(shù)據(jù),現(xiàn)在沒有調(diào)試成功,提示編碼錯(cuò)誤,這塊沒有經(jīng)驗(yàn) 請大神指導(dǎo)。import requestsfrom requests.auth import HTTPDigestAuthfd = open('defog.xml')dataxml = fd.read()auth = HTTPDigestAuth('admin', '1111')r = requests.put(url = cameraurl,data = dataxml, auth=auth)print r.status_codedefog.xml 文件的內(nèi)容如下:<Defog> <enbaled>false</enbaled> <defogStrength>0</defogStrength></Defog>報(bào)錯(cuò)如下: File "C:Python27libsite-packagesrequestsmodels.py", line 828, in content self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b'' File "C:Python27libsite-packagesrequestsmodels.py", line 753, in generate raise ChunkedEncodingError(e)requests.exceptions.ChunkedEncodingError: ("Connection broken: error(10054, '')", error(10054, ''))
1 回答

湖上湖
TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊
請求頭你改沒,試一下這個(gè)headers = {'content-type': 'application/xml'}
添加回答
舉報(bào)
0/150
提交
取消