以下网址(和其他类似的),可以在浏览器中打开,导致urllib2.urlopen抛出404异常:http://store.ovi.com/#/applications?categoryId=20&fragment=1&page=1urllib2.urlopen抛出404例外网址的浏览器打开
的getURL()返回相同的网址(不重定向)。头文件被复制并从萤火虫粘贴。我尝试将头文件作为字典传递给Request,但得到了相同的结果。 wget在控制台中打开url,但不是从脚本中打开。
的代码:
SOURCE_URL = 'http://store.ovi.com/#/applications?categoryId=20&fragment=1&page=2'
尝试:
socket.setdefaulttimeout(10)
hdrs = [('Host','store.ovi.com'),('User-Agent','Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13 AppEngine-Google;(+http://code.google.com/appengine)'),('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),('Accept-Language','en-us,en;q=0.5'),('Accept-Encoding','gzip,deflate'),('Accept-Charset','ISO-8859-1,utf-8;q=0.7,*;q=0.7'),('Keep-Alive','115'),('Connection','keep-alive'),('Cookie','JNPRSESSID=4u4devdrt7eb6e0qem3gin47i2; s_cc=true; undefined_s=First%20Visit; s_nr=1282817443274; s_sq=%5B%5BB%5D%5D; view=Grid; menu=menuOpen; OVI_DEVICE=b5130'),('Cache-Control','max-age=0')]
ree = urllib2.Request(source_url)
ree.addheaders = hdrs
opener = urllib2.build_opener()
htmlSource = opener.open(ree).read()
除了urllib2.HTTPError,E:
print e.code
print e.msg
print e.headers
误差输出:
未找到
日期:星期六,2010年8月28日0点36分57秒GMT
服务器:Apache/2.2.3(红帽)
X供电-者:PHP/5.2.2
过期:星期四,1981年11月19日08:52:00 GMT
缓存控制:无存储,无缓存,必须重新验证,后检查= 0,预检查= 0
pragma:no-cache
Keep-Alive:timeout = 7,max = 333
连接:Keep-Alive
传输编码:分块
Content-Type:text/html; charset = UTF-8
什么,如果有的话,我做错了吗?这是一个错误?如果是这样,是否有解决方法?谢谢!
在URL中的片段似乎搞乱事情 – aaronasterling 2010-08-28 01:15:52