How to fix tracebacks in Python from the "Python For Everybody" course

Hello!

I been taking the Python course on this platform for a few weeks and I been having difficulty finishing the exercises for File as Sequences and Python Lists lessons.

Pretty much, I been getting tracebacks in the line I write the “for loops” on the Atom iOS code editor. I don’t understand why I’m getting these tracebacks. I have edited and re-written the code multiple times, making sure the indentations is correct on each line, however, I still get a traceback.

This is the code I wrote on the Atom editor for the "Working with Lists " lesson

han = open(‘mbox-short.txt’)

for line in han:
line = line.rstrip()
wds = line.split()
print(‘Words:’,wds)
if len(wds) < 1 :
continue
if wds[0] != ‘From’ :
continue
print(wds[2])

This is the traceback

Traceback (most recent call last):
File “/Users/nati/Desktop/Python3/ex_08_01/Nati9.py”, line 3, in
for line in han:
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/codecs.py”, line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd1 in position 8: invalid continuation byte

This code is suppose to eliminate the lines on the file downloaded for this exercise.

If any of you in the forum has worked on this exercise can explain to me how I can fix this issue? I been getting the same issue for the last 2 exercises which I believe is not normal.

Thank you!

I appreciate your help!!!

This error isn’t related to indentation. Not entirely sure what’s going on here, but my first step would be taking a look at the mbox-short.txt file, if it was saved correctly and there isn’t any strange characters in it.

Thanks for your reply Sanity!

I was able to fix the issue. I went back to the website where I saved the file. I re-saved it as “Page Source” instead of “Web Archive” and then I went to the code and changed the name of the file like it was showing inside the folder in the code editor; “mbox.txt”.

Thanks for your help!!!