diff --git a/test/test_realtime.py b/test/test_realtime.py index ffeeba0..57ca527 100644 --- a/test/test_realtime.py +++ b/test/test_realtime.py @@ -12,7 +12,13 @@ def test_realtime_field(self): twstock.mock.get_stock_info('2330').keys()) def test_realtime_get_raw(self): - self.assertIn('msgArray', realtime.get_raw('2330')) + retry = 5 + for _ in range(retry): + stock = realtime.get_raw('2330') + if stock['rtcode'] == '0000' and stock['rtmessage'] != 'OK': + continue + self.assertIn('msgArray', realtime.get_raw('2330')) + break def test_realtime_get_blank(self): stock = realtime.get('') diff --git a/twstock/realtime.py b/twstock/realtime.py index 798378b..226a3fb 100644 --- a/twstock/realtime.py +++ b/twstock/realtime.py @@ -86,7 +86,7 @@ def get_raw(stocks) -> dict: return {'rtmessage': 'json decode error', 'rtcode': '5000'} -def get(stocks, retry=3): +def get(stocks, retry=10): # Prepare data data = get_raw(stocks) if not mock else twstock.mock.get(stocks) @@ -94,7 +94,7 @@ def get(stocks, retry=3): data['success'] = False # JSONdecode error, could be too fast, retry - if data['rtcode'] == '5000': + if data['rtcode'] == '0000': # XXX: Stupit retry, you will dead here if retry: return get(stocks, retry - 1)