3.35K 浏览
0

测试服务器连接不上? 实盘时会不会出现类似情况?

Traceback (most recent call last):
File “D:\Python37\lib\site-packages\urllib3\connectionpool.py”, line 603, in urlopen
chunked=chunked)
File “D:\Python37\lib\site-packages\urllib3\connectionpool.py”, line 344, in _make_request
self._validate_conn(conn)
File “D:\Python37\lib\site-packages\urllib3\connectionpool.py”, line 843, in _validate_conn
conn.connect()
File “D:\Python37\lib\site-packages\urllib3\connection.py”, line 370, in connect
ssl_context=context)
File “D:\Python37\lib\site-packages\urllib3\util\ssl_.py”, line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File “D:\Python37\lib\ssl.py”, line 412, in wrap_socket
session=session
File “D:\Python37\lib\ssl.py”, line 853, in _create
self.do_handshake()
File “D:\Python37\lib\ssl.py”, line 1117, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\Python37\lib\site-packages\requests\adapters.py”, line 449, in send
timeout=timeout
File “D:\Python37\lib\site-packages\urllib3\connectionpool.py”, line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File “D:\Python37\lib\site-packages\urllib3\util\retry.py”, line 368, in increment
raise six.reraise(type(error), error, _stacktrace)
File “D:\Python37\lib\site-packages\urllib3\packages\six.py”, line 685, in reraise
raise value.with_traceback(tb)
File “D:\Python37\lib\site-packages\urllib3\connectionpool.py”, line 603, in urlopen
chunked=chunked)
File “D:\Python37\lib\site-packages\urllib3\connectionpool.py”, line 344, in _make_request
self._validate_conn(conn)
File “D:\Python37\lib\site-packages\urllib3\connectionpool.py”, line 843, in _validate_conn
conn.connect()
File “D:\Python37\lib\site-packages\urllib3\connection.py”, line 370, in connect
ssl_context=context)
File “D:\Python37\lib\site-packages\urllib3\util\ssl_.py”, line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File “D:\Python37\lib\ssl.py”, line 412, in wrap_socket
session=session
File “D:\Python37\lib\ssl.py”, line 853, in _create
self.do_handshake()
File “D:\Python37\lib\ssl.py”, line 1117, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: (‘Connection aborted.’, OSError(0, ‘Error’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:\006.py”, line 38, in <module>
api = TqApi(backtest=TqBacktest(start_dt=date(2020, 3, 1), end_dt=date(2020, 4, 1)), web_gui=”:6666″)
File “D:\Python37\lib\site-packages\tqsdk\api.py”, line 240, in __init__
self._setup_connection() # 初始化通讯连接
File “D:\Python37\lib\site-packages\tqsdk\api.py”, line 1172, in _setup_connection
“quotes”: self._fetch_symbol_info(self._ins_url)
File “D:\Python37\lib\site-packages\tqsdk\api.py”, line 1229, in _fetch_symbol_info
rsp = requests.get(url, headers=self._base_headers, timeout=30)
File “D:\Python37\lib\site-packages\requests\api.py”, line 75, in get
return request(‘get’, url, params=params, **kwargs)
File “D:\Python37\lib\site-packages\requests\api.py”, line 60, in request
return session.request(method=method, url=url, **kwargs)
File “D:\Python37\lib\site-packages\requests\sessions.py”, line 533, in request
resp = self.send(prep, **send_kwargs)
File “D:\Python37\lib\site-packages\requests\sessions.py”, line 646, in send
r = adapter.send(request, **kwargs)
File “D:\Python37\lib\site-packages\requests\adapters.py”, line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: (‘Connection aborted.’, OSError(0, ‘Error’))
Task was destroyed but it is pending!
task: <Task pending coro=<TqApi._windows_patch() running at D:\Python37\lib\site-packages\tqsdk\api.py:1555> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending coro=<TqApi._notify_watcher() running at D:\Python37\lib\site-packages\tqsdk\api.py:1560> cb=[TqApi._on_task_done()]>
sys:1: RuntimeWarning: coroutine ‘TqApi._windows_patch’ was never awaited
sys:1: RuntimeWarning: coroutine ‘TqApi._notify_watcher’ was never awaited

Z Liu 发表新评论 2020年4月13日

知道了,谢谢!

我想测试时:第一次从服务器取数据,并保存到本地(数据库or文本);
第二次之后的所有测试从本地取数据,既加快了速度,又减少服务器负担。
能否给个代码例子?