讀取的字節字符串:bytestr.decode( 'UTF-8'),從文件返回的UnicodeDecodeError
>>> s = b'------WebKitFormBoundary02jEyE1fNXSRCL7D\r\nContent-Disposition: form-data; name="fileobj"; filename="3d15ef5126d4fa6631a863c29c5a741d.jpg"\r\nContent-Type: image/jpeg\r\n\r\n\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xe1\x006Exif\x00\x00II*'
>>> s
b'------WebKitFormBoundary02jEyE1fNXSRCL7D\r\nContent-Disposition: form-data; name="fileobj"; filename="3d15ef5126d4fa6631a863c29c5a741d.jpg"\r\nContent-Type: image/jpeg\r\n\r\n\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xe1\x006Exif\x00\x00II*'
>>> print(s.decode('utf8'))
Traceback (most recent call last):
File "<input>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 167: invalid start byte
爲什麼UnicodeDecodeError錯誤? s.decode('utf8')必須返回str對象?
好的,謝謝! s.partition(b'\ r \ n \ r \ n') - 這就是我需要的) – user1356067