[Errno 101] Network is unreachable
となっているので、network interfaceが起動しきる前にserviceが起動しているために、サーバーに接続しきれていないと思われます。
対応としては、以下の2つの方法が考えられます。
1. 自作プログラム上でネットワークが起動するまでリトライをする
2. serviceがネットワーク起動後に起動するように依存関係を設定する
1.の場合は、request.postにリトライ用のエラー処理を追加すれば良いかと思います。
例えば下記のコードのようにすれば、15秒待ってリトライを10回します。
import time
import equests.exceptions
retrycount = 0
while True:
try:
r = requests.post(url, data=json.dumps(sensorsdata), timeout=20)
except requests.exceptions.ConnectionError:
if retrycount > 10:
retrycount += 1
time.sleep(15)
continue
raise
2.の場合、systemd-networkd-wait-onlineを使うのがいいかと思います
この記事が参考になるかとおもいます。
https://kernhack.hatenablog.com/entry/2014/09/20/110938
Like!