Importing Image

0 votes

Hello guys, when I import an image it shows: 

UnicodeDecodeError: "utf-8" codec can"t decode byte 0xa0 in position 10: invalid start byte
code:
def importImage():
    result[0] = filedialog.askopenfile(mode = 'r', title = "Select file", initialdir =      "/home/amine/Bureau/desktop", filetypes = (("jpg files", ".jpg"), ("all files", ".*")))
    openImage = Image.open(result[0])
    resiszeImage = openImage.resize((247, 248))
    myImage = PhotoImage(resiszeImage)
    uploadCnavs.config(image = myImage)
Jun 25, 2020 in Python by Amine
• 120 points

edited Jun 25, 2020 by MD 727 views

1 answer to this question.

0 votes

Hi@Amine,

The error is because there is some non-ASCII character and it can't be encoded/decoded.  One simple way to avoid this error is to encode such strings. You can use the below line in your code. 

openImage = Image.open(result[0],encoding="utf8")
answered Jun 25, 2020 by MD
• 95,460 points

Related Questions In Python

+1 vote
2 answers

How to resize the image canvas to maintain a square aspect ratio

down voteacceptedUsing OpenCVYou can use resize() in OpenCV to ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points

edited Jul 11, 2023 by Khan Sarfaraz 1,691 views
0 votes
1 answer

How to resize image canvas to maintain square aspect ratio in Python, OpenCv

Building on Alexander-Reynolds answer above, here is ...READ MORE

answered Sep 4, 2018 in Python by Priyaj
• 58,020 points
5,220 views
0 votes
1 answer

How to save Numpy array as image in python?

If you have matplotlib, you can do: import ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
8,980 views
0 votes
1 answer

Need help checking the validity of an image file in Python

I went through the Python documentation and ...READ MORE

answered Jan 18, 2019 in Python by Nymeria
• 3,560 points
2,326 views
0 votes
1 answer

Convert HTML to an image in Python

webkit2png. The original version is OSX-only, but luckily ...READ MORE

answered Feb 5, 2019 in Python by SDeb
• 13,300 points
18,417 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,465 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,125 views
+1 vote
1 answer

tensorflow is installed but theres an error while importing

Hi@Christlan, This problem is related to version. Follow ...READ MORE

answered Dec 22, 2020 in Python by MD
• 95,460 points
13,691 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP