代码如下:
import tornado.httpclient
http_client = tornado.httpclient.HTTPClient()
response = http_client.fetch("www.baidu.com")
print(response.body)
http_client.close()
完整报错如下:
Traceback (most recent call last):
File "test.py", line 8, in <module>
response = http_client.fetch("www.baidu.com")
File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/tornado/httpclient.py", line 119, in fetch
self._async_client.fetch, request, **kwargs))
File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/tornado/ioloop.py", line 576, in run_sync
return future_cell[0].result()
File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/tornado/simple_httpclient.py", line 243, in run
self.request.url)
ValueError: Unsupported url scheme: www.baidu.com
Exception ignored in: <bound method HTTPClient.__del__ of <tornado.httpclient.HTTPClient object at 0x7f87e64760f0>>
Traceback (most recent call last):
File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/tornado/httpclient.py", line 99, in __del__
File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/tornado/httpclient.py", line 104, in close
File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/tornado/simple_httpclient.py", line 139, in close
File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/tornado/httpclient.py", line 220, in close
RuntimeError: inconsistent AsyncHTTPClient cache
解决方案:
response = http_client.fetch("www.baidu.com")
改为:
response = http_client.fetch("http://www.baidu.com")