gabrielfalcao / HTTPretty

Intercept HTTP requests at the Python socket level. Fakes the whole socket module
https://httpretty.readthedocs.org
MIT License
2.11k stars 275 forks source link

PUT request with encrypted body raises UTF-8 decode error #152

Open gataky opened 10 years ago

gataky commented 10 years ago

I'm trying to do a PUT request with an encrypted body and getting a decode error

UnicodeDecodeError: 'utf8' codec can't decode byte 0xed in position 0: invalid continuation byte

and the last bit of the traceback is

/usr/local/lib/python2.7/dist-packages/httpretty/utils.pyc in decode_utf8(s)
     40 def decode_utf8(s):
     41     if isinstance(s, byte_type):
---> 42         s = s.decode("utf-8")
     43 
     44     return text_type(s)

/usr/lib/python2.7/encodings/utf_8.pyc in decode(input, errors)
     14 
     15 def decode(input, errors='strict'):
---> 16     return codecs.utf_8_decode(input, errors, True)
     17 
     18 class IncrementalEncoder(codecs.IncrementalEncoder):

Looks like HTTPretty is trying to decode my body as UTF-8 but my body has no encoding. If I was to comment out 41-44 in utils.py and return s it works as I would expected. I don't know much about encoding and am hesitant to suggest a solution, but should this be so strict? Is it possible to just do a try except here?

kdeldycke commented 10 years ago

Likely fixed by 79fbacfd7d45578f8910a1ca0217e1d2d564e656 .