TSMPPT60へのget requestでコケると以降通信できない
Closed this issue · 3 comments
dodo5522 commented
2016/10/21 PM 5:48:57 solar_monitor DEBUG: KeenIoEventHandler sent data to keenio at 2016-10-21 08:48:55.438408
2016/10/21 PM 5:59:00 solar_monitor DEBUG: HTTPConnectionPool(host='192.168.1.20', port=80): Max retries exceeded with url: /MBCSV.cgi?ID=1&F=4&AHI=0&ALO=0&RHI=0&RLO=1 (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0xb07c8b10>, 'Connection to 192.168.1.20 timed out. (connect timeout=5)')) error!!!
2016/10/21 PM 6:08:56 solar_monitor DEBUG: 2016-10-21 09:08:55.824142: Battery, Charge Current, -0.0390625[A]
dodo5522 commented
import requests.exceptions as exc
dir(exc)
['BaseHTTPError',
'ChunkedEncodingError',
'ConnectTimeout',
'ConnectionError',
'ContentDecodingError',
'FileModeWarning',
'HTTPError',
'InvalidSchema',
'InvalidURL',
'MissingSchema',
'ProxyError',
'ReadTimeout',
'RequestException',
'RequestsWarning',
'RetryError',
'SSLError',
'StreamConsumedError',
'Timeout',
'TooManyRedirects',
'URLRequired',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__spec__']
try:
requests.get("http://aaa.bbb/index.html")
except (exc.ConnectionError, exc.Timeout, exc.ConnectTimeout, exc.HTTPError) as e:
print(type(e).__name__)
print(e)
ConnectionError
HTTPConnectionPool(host='aaa.bbb', port=80): Max retries exceeded with url: /index.html (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x1115ca8d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
dodo5522 commented
import requests.exceptions as req_exc
try:
requests.get("http://aaa/MBCSV.cgi")
except (req_exc.ConnectTimeout, req_exc.ConnectionError, req_exc.HTTPError, req_exc.ReadTimeout, req_exc.RequestException, req_exc.RetryError, req_exc.SSLError, req_exc.Timeout, req_exc.TooManyRedirects) as e:
# retry to connect
logger.error(type(e).__name__)
のような感じだろうか。
dodo5522 commented
うまくいった。
チャージコントローラとのセッションが切れた後再接続して動作を継続するようになった。
2016/11/12 AM 12:59:35 solar_monitor DEBUG: Counter, Amp Hours, 31667.7[Ah]
2016/11/12 AM 1:09:39 solar_monitor DEBUG: Exception raised at running target function: ConnectTimeout
2016/11/12 AM 1:09:39 solar_monitor DEBUG: Detail: HTTPConnectionPool(host='192.168.1.20', port=80): Max retries exceeded with url: /MBCSV.cgi?ID=1&F=4&AHI=0&ALO=
29&RHI=0&RLO=1 (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0xb05113f0>, 'Connection to 192.168.1.20 timed out. (c
onnect timeout=5)'))
2016/11/12 AM 1:19:35 solar_monitor DEBUG: Battery, Battery Voltage, 23.75244140625[V]
2016/11/12 AM 1:19:35 solar_monitor DEBUG: Array, Array Voltage, 0.3021240234375[V]
2016/11/12 AM 1:19:35 solar_monitor DEBUG: Counter, Kilowatt Hours, 574[kWh]
2016/11/12 AM 1:19:35 solar_monitor DEBUG: Array, Array Current, 0.0[A]