mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge branch 'fixencodings' of https://github.com/jerem/requests into develop
This commit is contained in:
+5
-3
@@ -179,12 +179,12 @@ def unicode_from_html(content):
|
||||
def stream_decode_response_unicode(iterator, r):
|
||||
"""Stream decodes a iterator."""
|
||||
encoding = get_encoding_from_headers(r.headers)
|
||||
if encoding is None:
|
||||
try:
|
||||
decoder = codecs.getincrementaldecoder(str(encoding))(errors='replace')
|
||||
except LookupError:
|
||||
for item in iterator:
|
||||
yield item
|
||||
return
|
||||
|
||||
decoder = codecs.getincrementaldecoder(encoding)(errors='replace')
|
||||
for chunk in iterator:
|
||||
rv = decoder.decode(chunk)
|
||||
if rv:
|
||||
@@ -219,6 +219,8 @@ def get_unicode_from_response(r):
|
||||
return unicode(r.content, encoding)
|
||||
except UnicodeError:
|
||||
tried_encodings.append(encoding)
|
||||
except LookupError:
|
||||
return r.content
|
||||
|
||||
# Fall back:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user