实时获取数据更新通知会断线和挂掉

使用官网的seatable,利用websocket功能获取实时数据更新,监测到会自动掉线,服务自动挂掉
有一个钟有两个钟的,使用系统定时功能关闭py文件重新运行有时又会遇到超过次数等报错限制

想请教下:
1)官网版本、开发者版本的websocket能否长期让SocketIO服务监听着
2)websocket是否有各种对应状态返回,启动成功是connection established,失败或者拒绝能否有状态返回

现遇到的错有:Failed to establish a new connection, connection refused以及用着用着就自动关了没有报错

  1. 看了下seatable api库,with_socket_io connet后能不能return一些状态信息呢,像connect、drop之类的,就可以判断,现在都是直接print了
  2. established建立完成后,在等UPDATE_DTABLE数据返回时,确实会无缘无故的断开,在单机调试程序时都有这种情况,就程序直接结束了

1,当前状态信息是直接 print。这里可以重写 ‘connect’, ‘disconnect’ 等事件(类似重写 UPDATE_DTABLE),实现自定义触发操作。

2,猜测可能是重写 on_update 函数里面的异常导致程序退出。建议和手册中的示例一样,使用 try except 将内容包起来。实时获取数据更新通知 - SeaTable 编程手册
无论是断开客户端网路,或服务端重启,脚本都可以自动重新连接。

2022-11-24 12:06:28.348916 [ SeaTable SocketIO on UPDATE_DTABLE ]
{"op_type":"modify_row","table_id":"0000","row_id":"fVnj1C-KTCW5o0WdHQT98g","updated":{"0000":"3","_last_modifier":"4b5d2d0836514857aea89539dc9808a3@auth.local"},"old_row":{"0000":"1"}}

2022-11-24 12:07:18.294379 [ SeaTable SocketIO connection dropped ]
2022-11-24 12:07:19.187624 [ SeaTable SocketIO connection error ] Connection refused by the server
2022-11-24 12:07:20.830714 [ SeaTable SocketIO connection error ] Connection refused by the server
2022-11-24 12:07:24.842123 [ SeaTable SocketIO connection error ] Connection refused by the server
2022-11-24 12:07:30.199986 [ SeaTable SocketIO connection established ]
2022-11-24 12:07:37.031464 [ SeaTable SocketIO on UPDATE_DTABLE ]
{"op_type":"modify_row","table_id":"0000","row_id":"fVnj1C-KTCW5o0WdHQT98g","updated":{"0000":"2","_last_modifier":"4b5d2d0836514857aea89539dc9808a3@auth.local"},"old_row":{"0000":"3"}}```

非常感谢答复。

  1. 就on_update函数用了官网模板,有try,调试是没问的,掉线的基本都没有数据变化时挂掉的,等到有数据更新时才发现on update后的动作没执行

  2. 目前我是单文件运行了,设了每两小时检查进程,关闭重启,也增加了log,还没问题
    下面是log数据,不知道算不算正常

    2022-11-24 15:57:34,861 Unexpected status code 502 in server response, aborting
    2022-11-24 15:57:34,861 Exiting write loop task
    2022-11-24 15:57:38,584 HTTP GET request to https://dtable-server-02.seatable.cn/socket.io/?dtable_uuid=cc06ff18-b9e3-4bd5-b5db-d0831f7bf648&transport=polling&EIO=3&sid=7nV1kzvA1sP1rIkBAHMD&t=1669276628.571 failed with error HTTPSConnectionPool(host=‘dtable-server-02.seatable.cn’, port=443): Read timed out. (read timeout=30.0).
    2022-11-24 15:57:38,584 Connection refused by the server, aborting
    2022-11-24 15:57:38,584 Waiting for write loop task to end
    2022-11-24 15:57:38,584 Waiting for ping loop task to end
    2022-11-24 15:57:38,584 Exiting ping task
    2022-11-24 15:57:38,584 Exiting read loop task
    2022-11-24 16:00:02,590 Starting new HTTPS connection (1): cloud.seatable.cn:443
    2022-11-24 16:00:02,849 https://cloud.seatable.cn:443 “GET /api/v2.1/dtable/app-access-token/ HTTP/1.1” 200 None
    2022-11-24 16:00:02,851 Attempting polling connection to https://dtable-server-02.seatable.cn/socket.io/?dtable_uuid=cc06ff18-b9e3-4bd5-b5db-d0831f7bf648&transport=polling&EIO=3
    2022-11-24 16:00:02,852 Starting new HTTPS connection (1): dtable-server-02.seatable.cn:443
    2022-11-24 16:00:03,065 https://dtable-server-02.seatable.cn:443 “GET /socket.io/?dtable_uuid=cc06ff18-b9e3-4bd5-b5db-d0831f7bf648&transport=polling&EIO=3&t=1669276802.8512259 HTTP/1.1” 200 None
    2022-11-24 16:00:03,065 Polling connection accepted with {‘sid’: ‘pzgc0AWJe6BqKXmzAJAE’, ‘upgrades’: [‘websocket’], ‘pingInterval’: 25000, ‘pingTimeout’: 5000}
    2022-11-24 16:00:03,065 Engine.IO connection established
    2022-11-24 16:00:03,065 Received packet MESSAGE data 0
    2022-11-24 16:00:03,066 Namespace / is connected
    2022-11-24 16:00:03,066 websocket-client package not installed, only polling transport is available
    2022-11-24 16:00:03,066 Emitting event “join-room” [/]
    2022-11-24 16:00:03,066 Sending packet PING data None
    2022-11-24 16:00:03,066 Sending packet MESSAGE data 2[“join-room”,“cc06ff18-b9e3-4bd5-b5db-d0831f7bf648”,“eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2Njk1MzYwMDIsImR0YWJsZV91dWlkIjoiY2MwNmZmMTgtYjllMy00YmQ1LWI1ZGItZDA4MzFmN2JmNjQ4IiwidXNlcm5hbWUiOiIiLCJwZXJtaXNzaW9uIjoicnciLCJhcHBfbmFtZSI6IndlYnNvY2tldCJ9.8c78PPD2yATA7gIo6IXYcacFO62sVXF0-FSrfk8XWew”]
    2022-11-24 16:00:03,069 Sending polling GET request to https://dtable-server-02.seatable.cn/socket.io/?dtable_uuid=cc06ff18-b9e3-4bd5-b5db-d0831f7bf648&transport=polling&EIO=3&sid=pzgc0AWJe6BqKXmzAJAE

  3. 我之前写在flask服务里,on update dtable阻塞写在线程里,感觉好像就是新开了线程,这里有问题
    不知道能否指点写,把它再写回flask里,不用单文件运行

    Thread(target=self.run_socket).start()
    def run_socket(self):
    # 以下阻塞等待接收数据
    self.base.socketIO.on(UPDATE_DTABLE, self.on_update)
    self.base.socketIO.wait()此本文本将被隐藏

由于这个功能直接使用了 socketio 库,可以查阅官方文档 (https://python-socketio.readthedocs.io)寻找如何集成到 flask 中。

你好,能帮忙解释下图上12点20点14点的问题吗,目前总有收不到实时通知

  1. 运行socket服务的文件一直开着,通过logging监控,到12点20时就出现这些exiting,1点多在表格中增加数据就没有接受到实时通知
  2. 14点是设置了每个两小时关闭服务再重启,重启后又能实时通知了
  3. 基本每天都会有表格更新了没有通知,所以才设置了每隔两小时关闭服务后再重启,但还是会遇到一些点,能否帮忙看看具体是怎么回事呢,谢谢