我正在使用 Python Requests 包来编写一个简单的 rest 客户端。这是我的代码 -
r = requests.get(url, auth=(user, passwd), stream=True, verify=False)
print('headers: ')
pprint.pprint(r.headers)
print('status: ' + str(r.status_code))
print('text: ' + r.text)
这是输出 -
headers:
{'content-type': 'text/xml;charset=UTF-8',
'date': 'Thu, 16 May 2013 03:26:06 GMT',
'server': 'Apache-Coyote/1.1',
'set-cookie': 'JSESSIONID=779FC39...5698; Path=/; Secure; HttpOnly',
'transfer-encoding': 'chunked'}
status: 200
Traceback (most recent call last):
File "C:\...\client.py", line 617, in _readinto_chunked
chunk_left = self._read_next_chunk_size()
File "C:\...\client.py", line 562, in _read_next_chunk_size
return int(line, 16)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 0: invalid continuation byte
对该请求的响应是 XML。好像是分块的。有没有一种特殊的方法来读取分块响应?我想将整个 XML 响应放在一个字符串中。