[英]python3.9 websocket error (discord gateway)
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")
異常在線程開始時被忽略:<function heartbeat at 0x00000236C458D3A0> 回溯(最近一次調用最后一次):文件“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(data) 文件“C:\\Users\\pc\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\websocket_core.py”中,行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 () 文件“C:\\Users\\pc\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\websocket_socket.py”,第 152 行,在 _send re 轉 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]
工作正常一段時間但我收到錯誤並且連接已關閉我做錯了什么?
關鍵在於堆棧跟蹤中的最終錯誤消息: ConnectionAbortedError: [WinError 10053]
。 您可以在此處找到該問題的答案: ConnectionAbortedError: [WinError 10053] 已建立的連接被主機中的軟件中止
在以后的帖子中,請直接在帖子中包含源代碼而不是圖像,並且請以 ``` 格式輸入錯誤輸出,以便它是等寬的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.