Catching Firebase 504网关超时[Python]

问题描述 投票:0回答:1

我正在构建一个简单的IOT设备(带有Raspberry Pi Zero),该设备每1秒从Firebase Realtime Database中提取数据并检查更新。

但是,在一定时间后(不确定确切的时间,但是在1小时到3小时之间),程序会退出,并显示504 Server Error: Gateway Time-out消息。我无法确切了解为什么会这样,我尝试通过断开Pi与互联网的连接来重新创建此错误,但未收到此消息。相反,该程序只是在ref.get()行中暂停,并在恢复连接后自动恢复运行。

此设备应始终处于打开状态,因此理想情况下,如果出现某种错误,我想重新启动程序/重新启动连接/重新启动Pi。有没有办法实现这样的目标?

似乎该消息实际上是由firebase_admin软件包生成的。

这里是错误消息:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 944, in request
    return super(_Client, self).request(method, url, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 105, in request
    resp.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 504 Server Error: Gateway Time-out for url: https://someFirebaseProject.firebaseio.com/someRef/subSomeRef/payload.json

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Desktop/project/main.py", line 94, in <module>
    lastUpdate = ref.get()['lastUpdate']
  File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 223, in get
    return self._client.body('get', self._add_suffix(), params=params)
  File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 117, in body
    resp = self.request(method, url, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 946, in request
    raise _Client.handle_rtdb_error(error)
firebase_admin.exceptions.UnknownError: Internal server error.
>>> 
python firebase firebase-realtime-database raspberry-pi traceback
1个回答
0
投票

要重新启动整个Raspberry Pi,您只需运行一个shell命令:

import os
os.system("sudo reboot")

我也有这个问题,通常会感到比较安全,但是有明显的缺点。我会尝试以类似方式重置wifi连接或网络接口

© www.soinside.com 2019 - 2024. All rights reserved.