Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python EncodeDecode error
#1
Hi !
I'm trying to manipulate images but I can't get rid of that error :

fichier=open("photo.jpg","r")

lignes=fichier.readlines()
Traceback (most recent call last):

  File "<ipython-input-32-87422df77ac2>", line 1, in <module>
    lignes=fichier.readlines()

  File "C:\Winpython\python-3.5.4.amd64\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 207: character maps to <undefined>
I've seen forums where people say to add encoding='utf-8' in the "open ..." but that won't work
Reply
#2
jpg is a binary file.
Unlike normal/pain text files an image file does not have any encoding,the data shown is a visual representation of the binary equivalent of the image.
Use rb and wb.
fichier = open("photo.jpg", "rb")
There are several libraries for manipulate images in Python,eg the most known Pillow.
Reply
#3
thanks ! it works now !
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020