Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

urllib - Why can't I get Python's urlopen() method to work on Windows?

Why isn't this simple Python code working?

import urllib
file = urllib.urlopen('http://www.google.com')
print file.read()

This is the error that I get:

Traceback (most recent call last):
  File "C:workspaceGarchUpdatesrcPractice.py", line 26, in <module>
    file = urllib.urlopen('http://www.google.com')
  File "C:Python26liburllib.py", line 87, in urlopen
    return opener.open(url)
  File "C:Python26liburllib.py", line 206, in open
    return getattr(self, name)(url)
  File "C:Python26liburllib.py", line 345, in open_http
    h.endheaders()
  File "C:Python26libhttplib.py", line 892, in endheaders
    self._send_output()
  File "C:Python26libhttplib.py", line 764, in _send_output
    self.send(msg)
  File "C:Python26libhttplib.py", line 723, in send
    self.connect()
  File "C:Python26libhttplib.py", line 704, in connect
    self.timeout)
  File "C:Python26libsocket.py", line 514, in create_connection
    raise error, msg
IOError: [Errno socket error] [Errno 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've tried it with several different pages but I can never get the urlopen method to execute correctly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your code is not the problem here.

Do you have any Proxy settings in your IE?

This says the python documentation for urllib.urlopen:

In a Windows environment, if no proxy environment variables are set,
proxy settings are obtained from the registry's Internet Settings
section.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...