3

Windows 7, Python 3.4, PyCharm Community Edition 3.1.1

I'm new to Python. I want to get the html of a website. I use the following code:

from urllib.request import urlopen
response = urlopen('http://python.org/')
html = response.read()

But I get the following error:

urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

I believe, the problem might come from this:

>>> import urllib
>>> urllib.request.getproxies()
{}

Any ideas, if that is the problem and how can I fix it?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
Trenera
  • 1,435
  • 7
  • 29
  • 44
  • @ alfasin: Can you please tell me what is returned when you enter the following commands in the python console? >>> import urllib >>> urllib.request.getproxies() – Trenera May 23 '14 at 10:21
  • It looks like your Puthon installation is brocken, because it fails to import the default packages. You should re-download the newest version and retry. Also, are you behind a proxy? – Alex Kulinkovich May 23 '14 at 10:27
  • I don't have any reasons to believe that it is broken. I believe I just haven't set the proxies. I'm on a company computer, so I have no idea what the connection is... – Trenera May 23 '14 at 10:31
  • possible duplicate of [Python: URLError: – Alex Kulinkovich May 23 '14 at 10:51
  • Those posts simply confirm that the problem is that there is no proxy, as I have said here, but doesn't explain how to set one... – Trenera May 23 '14 at 11:00
  • If you looked at linked post, you could understand, that it is not the problem of your code or Python! It is just the problem of your local environment settings. Look at this [post](http://stackoverflow.com/questions/2923703/why-cant-i-get-pythons-urlopen-method-to-work-on-windows) also. You should learn and discover the topic of proxy. – Alex Kulinkovich May 23 '14 at 13:19
  • Vihar, take a look at the answer to this post: http://stackoverflow.com/questions/5620263/using-an-http-proxy-python it explains how to build an urllib2 urlopener which uses a proxy (or how to use `requests`). – supakeen May 23 '14 at 13:29

0 Answers0