这个使用tornado的脚本在一些实时主机上获得http响应代码500。请不要介意这个循环。这是因为我的代码块过于简单化。我试过使用ip,但没有用。你知道吗
#!/usr/bin/python
import tornado
from tornado import httpclient
from tornado import gen
from tornado.httpclient import AsyncHTTPClient
gloop = tornado.ioloop.IOLoop.instance()
@gen.engine
def process(url):
print url
try:
http_client = httpclient.AsyncHTTPClient()
request = tornado.httpclient.HTTPRequest(url=str(url), connect_timeout=5.0, validate_cert = False, request_timeout=5.0, follow_redirects=True)
response = yield tornado.gen.Task(http_client.fetch, request)
print url
print response.code
if response.error: raise Exception(response.error)
except Exception as e:
print e
gloop.add_callback(process, 'http://www.dhlsameday.com')
tornado.httpclient.AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
gloop.start()
尽管存在不可信的证书。起初我怀疑对机器人程序来说是安全的,但是这个网站在错误处理方面有问题,它需要
Accept-Language
。即使是卷发也会失败。要开始工作,只需传递标题:我建议添加更常见的浏览器标题
相关问题 更多 >
编程相关推荐