English 中文(简体)
python3.9 网上备案错误(出入门口)
原标题: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")
Exception ignored in thread started by: <function heartbeat at 0x00000236C458D3A0>
Traceback (most recent call last):
  File "C:UserspcDesktop	estwebsoket.py", line 38, in heartbeat
    send_json_request(ws, heartbeatJSON)
  File "C:UserspcDesktop	estwebsoket.py", line 16, in send_json_request
    ws.send(json.dumps(request))
  File "C:UserspcAppDataLocalProgramsPythonPython39libsite-packageswebsocket\_core.py", line 282, in send
    return self.send_frame(frame)
  File "C:UserspcAppDataLocalProgramsPythonPython39libsite-packageswebsocket\_core.py", line 310, in send_frame
    l = self._send(data)
  File "C:UserspcAppDataLocalProgramsPythonPython39libsite-packageswebsocket\_core.py", line 514, in _send
    return send(self.sock, data)
  File "C:UserspcAppDataLocalProgramsPythonPython39libsite-packageswebsocket\_socket.py", line 175, in send
    return _send()
  File "C:UserspcAppDataLocalProgramsPythonPython39libsite-packageswebsocket\_socket.py", line 152, in _send
    return sock.send(data)
  File "C:UserspcAppDataLocalProgramsPythonPython39libssl.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?

问题回答

关键在于中分光中的最后错误信息:Connection 流产 rror: [WinError 10053]。 您可在此找到这一问题的答案:。 联系人 错误:[WinError 10053] 该软件在你的主机上用了固定的链接。

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.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签