Python3 Error: TypeError: Can’t convert ‘bytes’ object to str implicitly

urlopen() returns a bytes object, to perform string operations over it you should convert it to str first.

for word in urlopen(WORD_URL).readlines():
    WORDS.append(word.strip().decode('utf-8')) # utf-8 works in your case

To get the correct charset : How to download any(!) webpage with correct charset in python?

Leave a Comment