Skip to content

Tag: urllib2

Alternative of urllib.urlretrieve in Python 3.5

I am currently doing a course on machine learning in UDACITY . In there they have written some code in python 2.7 but as i am currently using python 3.5 , i am getting some error . This is the code I tried urllib.request . But still gives me error . I am using PyCharm as my IDE . Answer

python urllib2 and unicode

I would like to collect information from the results given by a search engine. But I can only write text instead of unicode in the query part. give this error Answer Encode the Unicode data to UTF-8, then URL-encode: Demo: Using urllib.urlencode() to build the parameters is easier, but you can also just escap…

How do I catch a specific HTTP error in Python?

I have but what I end up is catching any kind of HTTP error. I want to catch only if the specified webpage doesn’t exist (404?). Answer Python 3 Python 2 Just catch HTTPError, handle it, and if it’s not Error 404, simply use raise to re-raise the exception. See the Python tutorial. Here is a compl…