PythonでAPIでhttp通信しようとすると1500回に一度程度に「RemoteDisconnected」と通信エラーが出て止まってしまいます。
try & except を使ってエラーが出たときに接続再試行すればよいのですが、try & except に引っ掛かってくれません。
except RemoteDisconnected : でも
except http.client.RemoteDisconnected : でも
except http.client.RemoteDisconnected as e: でもダメでした。
exceptのあとに続くものを教えていただきたいです。
ご教授よろしくお願い致します。
python
1import http 2from http.client import RemoteDisconnected 3 4try: 5 kline = ccxtBybit.public_get_kline_list({"symbol":"BTCUSD","interval":"1", "from":int(time.time())-120}) 6except http.client.RemoteDisconnected as e: 7 print("connect error!!") 8 continue
エラー全体
Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen httplib_response = self._make_request( File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 426, in _make_request six.raise_from(e, None) File "<string>", line 3, in raise_from File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request httplib_response = conn.getresponse() File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1347, in getresponse response.begin() File "C:\ProgramData\Anaconda3\lib\http\client.py", line 307, in begin version, status, reason = self._read_status() File "C:\ProgramData\Anaconda3\lib\http\client.py", line 276, in _read_status raise RemoteDisconnected("Remote end closed connection without" http.client.RemoteDisconnected: Remote end closed connection without response During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen retries = retries.increment( File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 410, in increment raise six.reraise(type(error), error, _stacktrace) File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\packages\six.py", line 734, in reraise raise value.with_traceback(tb) File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen httplib_response = self._make_request( File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 426, in _make_request six.raise_from(e, None) File "<string>", line 3, in raise_from File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request httplib_response = conn.getresponse() File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1347, in getresponse response.begin() File "C:\ProgramData\Anaconda3\lib\http\client.py", line 307, in begin version, status, reason = self._read_status() File "C:\ProgramData\Anaconda3\lib\http\client.py", line 276, in _read_status raise RemoteDisconnected("Remote end closed connection without" urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 562, in fetch response = self.session.request( File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 530, in request resp = self.send(prep, **send_kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 643, in send r = adapter.send(request, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "bybit.py", line 63, in <module> kline = ccxtBybit.public_get_kline_list({"symbol":"BTCUSD","interval":"1", "from":int(time.time())-120}) File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 465, in inner return entry(_self, **inner_kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 490, in request return self.fetch2(path, api, method, params, headers, body) File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 486, in fetch2 return self.fetch(request['url'], request['method'], request['headers'], request['body']) File "C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 614, in fetch raise NetworkError(details) from e ccxt.base.errors.NetworkError: bybit GET https://api.bybit.com/v2/public/kline/list?symbol=BTCUSD&interval=1&from=1616989892
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/03/30 00:11