simple_httpclient: Timeout after redirect not raised properly
Hello, My test codes are below:
import traceback from tornado import httpclient
def test(): client = httpclient.HTTPClient() url = "http://www.baidu.com/link?url=7rwodBCaetm-ogDMm0fCdkj-Crje0M21LIWnXbz3XxToow8VmZwXOZaEz1nBMJBKofatc2X8SlFXyNvv5D7HhWgpIB8MDi5R85IYL30OjDmW4URWPW5y4AIwkVKioJSxPPBzWJmmaO11fEEO__BLxIiiT1FcKw8asqqF7h1QupS" try: response = client.fetch(url) print(response) except: traceback.print_exc()
if name == "main": test()
It is suspended after got tornado.simple_httpclient.HTTPTimeoutError. The stack trace is
ERROR:asyncio:Exception in callback _HTTPConnection.finish.
How to fix it? Thanks!
Python 3.8.5 Tornado 6.1
Try to run it several times to get above error
Did you try to open the URL in your web browser?
This looks like a bug when following redirects: some errors from the second request aren't getting raised correctly. This probably affects asynchronous usage as well as the synchronous HTTPClient, although I'm not certain. There are a couple of workarounds:
- Install pycurl and run
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")at the start of your program - Pass
follow_redirects=Falsetofetchand handle the redirect yourself.
AsyncHTTPClient also has the same error. The CurlAsyncHTTPClient works Thanks!