問(wèn)題:python使用requests庫(kù)實(shí)現(xiàn) http的put get。get現(xiàn)在沒(méi)有問(wèn)題,使用PUT時(shí) 需要攜帶xml的數(shù)據(jù),現(xiàn)在沒(méi)有調(diào)試成功,提示編碼錯(cuò)誤,這塊沒(méi)有經(jīng)驗(yàn) 請(qǐng)大神指導(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 contentself._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''File "C:Python27libsite-packagesrequestsmodels.py", line 753, in generateraise ChunkedEncodingError(e)requests.exceptions.ChunkedEncodingError: ("Connection broken: error(10054, '')", error(10054, ''))
1 回答

慕的地8271018
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
fd = open('defog.xml') 讀文件時(shí)使用open(path,encoding=’UTF-8’) ,先看看這個(gè)文件的編碼吧.
添加回答
舉報(bào)
0/150
提交
取消