0
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")

Exception ignored in thread started by: <function heartbeat at 0x00000236C458D3A0> Traceback (most recent call last): File "C:\Users\pc\Desktop\test\websoket.py", line 38, in heartbeat send_json_request(ws, heartbeatJSON) File "C:\Users\pc\Desktop\test\websoket.py", line 16, in send_json_request ws.send(json.dumps(request)) File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_core.py", line 282, in send return self.send_frame(frame) File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_core.py", line 310, in send_frame l = self._send(data) File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_core.py", line 514, in _send return send(self.sock, data) File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_socket.py", line 175, in send return _send() File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\site-packages\websocket_socket.py", line 152, in _send return sock.send(data) File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1173, in send return self._sslobj.write(data) ConnectionAbortedError: [WinError 10053]

works fine for some time But I get an error and the connection is closed What did I do wrong?

Joon1313
  • 1
  • 2

1 Answers1

0

The key is in the final error message in the stack trace: ConnectionAbortedError: [WinError 10053]. You can find an answer to that question here: ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

In future posts, please include the source code directly in the post rather than an image and please enter the error output in ``` format so that it is monospaced.

Mahyar Mirrashed
  • 471
  • 1
  • 3
  • 14