没有线程的多连接套接字无法识别发送

2024-09-28 19:01:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码中有这个错误,我不知道如何消除它。代码将多个套接字连接到同一个服务器,但是我得到了这个错误

Traceback (most recent call last):
  File "C:\Users\user\Desktop\file.py", line 73, in <module>
    connect_to(target, port)
  File "C:\Users\user\Desktop\file.py", line 68, in connect_to
    int_nob.send("User-Agent: {}\r\n".format(random.choice(user_agents)).encode("utf-8"))
AttributeError: 'NoneType' object has no attribute 'send

受影响的代码部分

def connect_to(ip, port1):
    int_nob = int(200)#num of bots
    for x in range(0, int_nob):
        print(int(int_nob))

        int_nob -= 1
        int_nob = s.connect((ip, port1))
        int_nob.send("User-Agent: {}\r\n".format(random.choice(user_agents)).encode("utf-8"))
        if int_nob == 0:
            print(list_of_sockets)
            print("resending sockets of " + int_nob)
while True:
    connect_to(target, port)

我有所有的钱 import os import random s = socket.socket(AF_INET, socket.SOCK_STREM) port = 445

我也不使用线程


Tags: ofto代码insendportconnect错误