Alessandro
Alessandro

Reputation: 89

Python UnicodeDecodeError

I am building a little website crawler and I've encountered some problems with it. The first one would be Unicode characters in the url

Let's say I have the following url : http://putlocker.is/actor/Juan_Fern%C3%A1ndez

My code is :

        try:

             connection = urllib.urlopen(self.__link)
             get = connection.read().decode('utf8')


        except:
            if UnicodeDecodeError:
                 print("UnicodeDecodeError !!!")  

I'm talkink about the original link , not about the encoded one

Upvotes: 0

Views: 185

Answers (1)

pss
pss

Reputation: 744

Your way of error handling seems to be wrong. Expression under your if-statement UnicodeDecodeError will always be True. You probably should change it to

try:
    ...
except UnicodeDecodeError:
    #handle error

In your case any error is just swallowed so you don't even see what the actual error is.

Upvotes: 1

Related Questions