[英]Catching Firebase 504 gateway timeout
I'm building a simple IOT device (with a Raspberry Pi Zero) which pulls data from Firebase Realtime Database every 1 second and checks for updates.我正在构建一个简单的 IOT 设备(带有 Raspberry Pi Zero),它每 1 秒从 Firebase 实时数据库中提取数据并检查更新。
However, after a certain time (not sure exactly how much but somewhere between 1 hour and 3 hours) the program exits with a 504 Server Error: Gateway Time-out
message.但是,在一段时间后(不确定具体多少,但在 1 小时到 3 小时之间),程序退出并显示
504 Server Error: Gateway Time-out
消息。 I couldn't understand exactly why this is happening, I tried to recreate this error by disconnecting the Pi from the internet and I did not get this message.我不明白为什么会发生这种情况,我试图通过断开 Pi 与互联网的连接来重新创建此错误,但我没有收到此消息。 Instead, the program simply paused in a
ref.get()
line and automatically resumed running once the connection was back.相反,程序只是在
ref.get()
行中暂停,并在连接恢复后自动恢复运行。
This device is meant to be always on, so ideally if I get some kind of error, I would like to restart the program / reinitiate the connection / reboot the Pi.该设备应始终开启,因此理想情况下,如果我遇到某种错误,我想重新启动程序/重新启动连接/重新启动 Pi。 Is there a way to achieve something like this?
有没有办法实现这样的目标?
It seems like the message is actually generated by the firebase_admin package.似乎该消息实际上是由 firebase_admin package 生成的。
Here is the error message:这是错误消息:
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.
>>>
To reboot the whole Raspberry Pi, you can just run a shell command:要重新启动整个 Raspberry Pi,您只需运行 shell 命令:
import os
os.system("sudo reboot")
I've had this problem too and usually feel safer with that, but there's obvious downsides.我也遇到过这个问题,通常感觉更安全,但也有明显的缺点。 I'd try resetting the wifi connection or network interface in a similar way
我会尝试以类似的方式重置 wifi 连接或网络接口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.