websockets.exceptions 4040(私人使用),原因=耗尽连接--python
我的 websocket 连接上不断收到此错误
websockets.exceptions.ConnectionClosedError: code = 4040 (private use), reason = Draining connection
这是我的代码
bsc = 'wss://speedy-nodes-nyc.moralis.io/123456789/bsc/mainnet/ws'
web3 = Web3(Web3.WebsocketProvider(bsc))
print(web3.isConnected())
def handle_event(event):
#Web3.toJSON(event)
print(Web3.toJSON(event))
async def log_loop(event_filter, poll_interval):
while True:
for event in event_filter.get_new_entries():
handle_event(event)
await asyncio.sleep(poll_interval)
def main():
event_filter = myContract.events.Transfer.createFilter(fromBlock="latest")
#block_filter = web3.eth.filter('latest')
#tx_filter = web3.eth.filter('pending')
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(
asyncio.gather(
#log_loop(block_filter, 2),
#log_loop(tx_filter, 2)))
log_loop(event_filter, 2)))
finally:
loop.close()
if __name__ == '__main__':
main()
如果连接在不退出正在运行的脚本的情况下关闭,我如何自动重新连接到我的 websocketprovider?
我知道类似问题已有答案,但没有一个对我有用。
我还知道它在将 javascript 中的选项添加到 websocketprovider 时有效
reconnect: {
auto: true,
delay: 10000,
maxAttempts: 10,
}
我将如何在 python 中使用这些选项?
I keep getting this error on my websocket connection
websockets.exceptions.ConnectionClosedError: code = 4040 (private use), reason = Draining connection
This is my code
bsc = 'wss://speedy-nodes-nyc.moralis.io/123456789/bsc/mainnet/ws'
web3 = Web3(Web3.WebsocketProvider(bsc))
print(web3.isConnected())
def handle_event(event):
#Web3.toJSON(event)
print(Web3.toJSON(event))
async def log_loop(event_filter, poll_interval):
while True:
for event in event_filter.get_new_entries():
handle_event(event)
await asyncio.sleep(poll_interval)
def main():
event_filter = myContract.events.Transfer.createFilter(fromBlock="latest")
#block_filter = web3.eth.filter('latest')
#tx_filter = web3.eth.filter('pending')
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(
asyncio.gather(
#log_loop(block_filter, 2),
#log_loop(tx_filter, 2)))
log_loop(event_filter, 2)))
finally:
loop.close()
if __name__ == '__main__':
main()
How can I automatically reconnect to my websocketprovider if the connection closes without exiting my running script?
I know there have been answers to similliar questions but none of them work for me.
I also know that it works when adding options in javascript to the websocketprovider
reconnect: {
auto: true,
delay: 10000,
maxAttempts: 10,
}
How would I use these options in python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论