V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sbmzhcn
V2EX  ›  Python

tornado 产生的很奇怪的问题,只在 chrome 下产生,无法访问此网站

  •  
  •   sbmzhcn · 2016-08-03 16:09:07 +08:00 · 325 次点击
    这是一个创建于 2822 天前的主题,其中的信息可能已经有所发展或是发生改变。

    tornado 做了一个 Web 程序。使用 IE 访问没有任何问题,使用 chrome 访问其中一个页面会出现下面这个错误


    无法访问此网站

    连接已重置。 请试试以下办法: 重新加载网页 检查网络连接 检查代理服务器和防火墙 ERR_CONNECTION_RESET


    1 、在 chrome 下在这个页面出现错误时,同时用 ie 打开当前页面是可以的,没有任何问题

    2 、如果此网页翻墙,仍然没问题,打开正常

    3 、我直接输入的 IP ,当前 ip 没有被墙

    我访问的这个页面是使用 tornado 做的一个反向代理。

    代码大概如下:

    def fetch_request(url, callback, **kwargs):
        tornado.httpclient.AsyncHTTPClient.configure('tornado.curl_httpclient.CurlAsyncHTTPClient')
    
        req = tornado.httpclient.HTTPRequest(url, **kwargs)
        client = tornado.httpclient.AsyncHTTPClient()
        client.fetch(req, callback)
    
    
    class ProxyHandler(BaseHandler):
        @tornado.web.asynchronous
        def get(self, url):
            def handle_response(response):
                if (response.error and not
                        isinstance(response.error, tornado.httpclient.HTTPError)):
                    self.set_status(500)
                    self.write('Internal server error:\n' + str(response.error))
                else:
                    self.set_status(response.code, response.reason)
                    self._headers = tornado.httputil.HTTPHeaders() # clear tornado default header
    
                    for header, v in response.headers.get_all():
                        if header not in ('Content-Length', 'Transfer-Encoding', 'Content-Encoding', 'Connection'):
                            self.add_header(header, v) # some header appear multiple times, eg 'Set-Cookie'
    
                    body = response.body
                    if body:
                        # self.set_header('Content-Length', len(body))
                        self.write(body)
                self.finish()
            try:
                uri = self.request.uri
                url = uri.replace("/proxy/", "")
                #  headers=self.request.headers,
                fetch_request(
                    url, handle_response,
                    method=self.request.method, follow_redirects=False,
                    allow_nonstandard_methods=True)
            except tornado.httpclient.HTTPError as e:
                if hasattr(e, 'response') and e.response:
                    handle_response(e.response)
                else:
                    self.set_status(500)
                    self.write('Internal server error:\n' + str(e))
                    self.finish()
    
    3 条回复    2016-08-04 09:51:54 +08:00
    sbmzhcn
        1
    sbmzhcn  
    OP
       2016-08-03 22:02:28 +08:00
    初步判断是 https 的关系,仍需排查。。。
    gulu
        2
    gulu  
       2016-08-04 00:46:15 +08:00 via Android
    你是不是在做本地调试并且 chrome 开启了代理?
    sbmzhcn
        3
    sbmzhcn  
    OP
       2016-08-04 09:51:54 +08:00
    @gulu 和代理没关系,我关了代理,一样出这问题,已经排查过。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5559 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 03:07 · PVG 11:07 · LAX 20:07 · JFK 23:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.