Tôi chỉ muốn có một ý tưởng tốt hơn về những gì đang xảy ra ở đây, tôi có thể tất nhiên "làm việc xung quanh" vấn đề bằng cách sử dụng urllib2.tại sao urllib.urlopen (url) thất bại trong khi urllib2.urlopen (url) hoạt động. Điều gì đặc biệt về phản hồi của máy chủ đang gây ra điều này?
import urllib
import urllib2
url = "http://www.crutchfield.com/S-pqvJFyfA8KG/p_15410415/Dynamat-10415-Xtreme-Speaker-Kit.html"
# urllib2 works fine (foo.headers/foo.read() also behave)
foo = urllib2.urlopen(url)
# urllib throws errors though, what specifically is causing this?
bar = urllib.urlopen(url)
http://pae.st/AxDW/ cho biết mã này hoạt động với ngoại lệ/stacktrace. foo.headers
và foo.read()
làm việc tốt
[email protected] ~ $: curl -I "http://www.crutchfield.com/S-pqvJFyfA8KG/p_15410415/Dynamat-10415-Xtreme-Speaker-Kit.html"
HTTP/1.1 302 Object Moved
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Location: /S-FSTWJcduy5w/p_15410415/Dynamat-10415-Xtreme-Speaker-Kit.html
Server: Microsoft-IIS/7.5
Set-Cookie: SESSIONID=FSTWJcduy5w; domain=.crutchfield.com; expires=Fri, 22-Feb-2013 22:06:43 GMT; path=/
Set-Cookie: SYSTEMID=0; domain=.crutchfield.com; expires=Fri, 22-Feb-2013 22:06:43 GMT; path=/
Set-Cookie: SESSIONDATE=02/23/2012 17:07:00; domain=.crutchfield.com; expires=Fri, 22-Feb-2013 22:06:43 GMT; path=/
X-AspNet-Version: 4.0.30319
HostName: cws105
Date: Thu, 23 Feb 2012 22:06:43 GMT
Cảm ơn.
Dường như urllib.urlopen (url) hoạt động dưới 10% thời gian. hooray cho các máy chủ không xác định! –