Skip to content

TypeError: Object of type 'bytes' is not JSON serializable #3

Description

@liudongdong1

when i try this code,and i meet an error about encoding,and i dont know how to do with is?
``@itchat.msg_register([PICTURE])
def download_files(msg):
print('recieved')
parm_translation_origin_language = 'zh' # will be overwriten by TEXT_DETECTION
msg.download(msg.fileName)
print('\nDownloaded image file name is: %s' % msg['FileName'])
with open(msg['FileName'], "r") as image_file:
image_content = image_file.read()
return base64.b64encode(image_content)

and the error is:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\itchat\components\register.py", line 60, in configured_reply
r = replyFn(msg)
File "", line 10, in download_files
image_content = image_file.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence

i make some change,but it didn't work,
with open(msg['FileName'], "rb") as image_file:
image_content = image_file.read()
return base64.b64encode(image_content)
thank you for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions