Hệ điều hành: Windows 7; Python 2.7.3 bằng cách sử dụng Python GUI ShellPython: URLError: <urlopen error [Errno 10060]
Tôi đang cố gắng đọc một trang web thông qua Python và một số tác giả sử dụng thư viện urllib
và urllib2
. Để lưu trữ các trang web trong một biến, tôi đã nhìn thấy một cách tiếp cận tương tự như đề xuất:
import urllib
import urllib2
g = "http://www.google.com/"
read = urllib2.urlopen(g)
Dòng cuối cùng tạo ra một lỗi sau một 120 + giây:
> Traceback (most recent call last): File "<pyshell#27>", line 1, in
> <module>
> r = urllib2.urlopen(o) File "C:\Python27\lib\urllib2.py", line 126, in urlopen
> return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 400, in open
> response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 418, in _open
> '_open', req) File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
> result = func(*args) File "C:\Python27\lib\urllib2.py", line 1207, in http_open
> return self.do_open(httplib.HTTPConnection, req) File "C:\Python27\lib\urllib2.py", line 1177, in do_open
> raise URLError(err) URLError: <urlopen 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>
Tôi đã cố gắng bỏ qua các biến g
và cố gắng để urlopen("http://www.google.com/")
không có thành công hoặc (nó tạo ra cùng một lỗi sau cùng một khoảng thời gian).
Hoạt động tốt ở đây. Internet của bạn có hoạt động không? –
Nó hoạt động trên Win7 + Python2.7 của tôi. Vấn đề có thể xảy ra nhất là proxy. Xem thêm tại đây: http: //stackoverflow.com/questions/5620263/using-an-http-proxy-python http://stackoverflow.com/questions/2923703/why-cant-i-get-pythons-urlopen-method -to-work – Sheng
@Sheng Post đó là câu trả lời, vì đó là khả năng nhất đó là vấn đề. – Question3CPO