def download(source_url):
socket.setdefaulttimeout(10)
agents = ['Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)','Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)','Microsoft Internet Explorer/4.0b1 (Windows 95)','Opera/8.00 (Windows NT 5.1; U; en)']
ree = urllib2.Request(source_url)
ree.add_header('User-Agent',random.choice(agents))
resp = urllib2.urlopen(ree)
htmlSource = resp.read()
return htmlSource
url = "http://myIP/details/?id=4"
result_html = download(url)它不应该用10秒的超时来计时out...even。
发布于 2010-04-03 09:15:34
如果您正在运行开发服务器,这将失败,因为它是单线程的,并且它忙于处理原始请求。如果你想让它工作,可以用mod_wsgi或者CherryPy这样的东西。
发布于 2010-04-03 09:13:48
当您说“您自己的域”时,您是从NAT防火墙内部击中它的吗?
像这样的东西?
123.1.2.3 (公网myIP) <- NAT网关-> 192.168.1.5 (服务器内网IP ) <--> 192.168.1.10 (您)
许多防火墙不允许内部地址在不重写DNS的情况下访问外部接口。DNS重写会导致防火墙拦截您的DNS查找,并使用内网IP重写生成的公网IP。
https://stackoverflow.com/questions/2569886
复制相似问题