Skip to content
Advertisement

How to iterate the loop if the condition is not met

I am trying to get the id of respective movie name in that i need to check whether the url is working or not . If not then i need to append the movie name in the empty list

JavaScript

print(movie_buff_uuid)

if i passed the data2 in the above loop i am getting this error urllib.error.HTTPError: HTTP Error 404: Not Found to overcome this error. I have tried this

JavaScript

Expected output:

JavaScript

Any idea would be appreciated

Advertisement

Answer

As dominik-air said, you’re getting a 404 response when the file doesn’t exist. However Python’s built-in urllib raises an error when it gets this (unlike, for example, the justly popular requests library).

In Python generally we use try/catch flow to deal with this (EAFP).

Putting it all together:

JavaScript

(You don’t need dataframes in the first part either :) )

Advertisement