【问题标题】:python3.9 websocket error (discord gateway)python3.9 websocket错误(不和谐网关)
【发布时间】:2021-09-28 13:27:58
【问题描述】:
import websocket #pip install websocket-client
import json
import threading
import time

token_file = open("token.txt", "r")
token_read = token_file.read()
token_list = token_read.split()
token_file.close()
print(token_list)

def send_json_request(ws, request):
    ws.send(json.dumps(request))

def recieve_json_response(ws):
    response = ws.recv()
    if response:
        return json.loads(response)

def heartbeat(interval, ws):
    print('Heartbeat begin')
    while True:
        time.sleep(interval)
        heartbeatJSON = {
            "op": 1,
            "d": "null"
        }
        send_json_request(ws, heartbeatJSON)
        print("Heartbeat sent")

for index , v in enumerate(token_list):
    ws = websocket.WebSocket()
    ws.connect('wss://gateway.discord.gg/?v=6&encording=json')
    event = recieve_json_response(ws)

    heartbeat_interval = event['d']['heartbeat_interval'] / 1000
    threading._start_new_thread(heartbeat, (heartbeat_interval, ws))


    pis=1
    payload = {
        'op': 2,
        "d": {
            "token": v,
            "properties": {
                "$os": "windows",
                "$browser": "chrome",
                "$device": 'pc'
            }
        }
    }
    try:
        send_json_request(ws, payload)
    except:
        index += 1
        print(index, "error")

在由以下启动的线程中忽略的异常: 回溯(最近一次通话最后): 文件“C:\Users\pc\Desktop\test\websoket.py”,第 38 行,心跳 send_json_request(ws, heartbeatJSON) 文件“C:\Users\pc\Desktop\test\websoket.py”,第 16 行,在 send_json_request ws.send(json.dumps(request)) 文件“C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_core.py”,第 282 行,在发送中 返回 self.send_frame(frame) 文件“C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_core.py”,第 310 行,在 send_frame l = self._send(数据) _send 中的文件“C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_core.py”,第 514 行 返回发送(self.sock,数据) 文件“C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_socket.py”,第 175 行,发送 返回_发送() 文件“C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_socket.py”,第 152 行,在 _send 返回 sock.send(数据) 文件“C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\ssl.py”,第 1173 行,在发送中 返回 self._sslobj.write(data) ConnectionAbortedError:[WinError 10053]

可以正常工作一段时间但我收到错误并且连接已关闭 我做错了什么?

【问题讨论】:

    标签: python websocket discord


    【解决方案1】:

    关键在于堆栈跟踪中的最终错误消息:ConnectionAbortedError: [WinError 10053]。您可以在此处找到该问题的答案:ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

    在以后的帖子中,请直接在帖子中包含源代码而不是图像,并且请以```格式输入错误输出,以便它是等宽的。

    【讨论】:

      猜你喜欢
      • 2017-04-26
      • 1970-01-01
      • 2022-08-04
      • 2021-02-02
      • 1970-01-01
      • 2019-10-16
      • 2018-12-18
      • 2021-06-26
      • 2023-04-03
      相关资源
      最近更新 更多