gpt4 book ai didi

python - TypeError : str, 字节或字节数组预期,而不是列表

转载 作者:行者123 更新时间:2023-12-01 09:31:14 26 4
gpt4 key购买 nike

所以我尝试从文本文件中提取一些 IP 并在套接字连接中使用该列表。我的问题是我不断收到以下错误:

类型错误:需要 str、字节或字节数组,而不是列表

这是我使用的代码:

    import socket

ips = open('list.txt', 'r').readlines()

def displayType(sec_type):
switcher = {
0: "1",
1: "2",
2: "3"
}
print(' type: ' + str(sec_type) + ' (' + switcher.get(sec_type,"Not defined by IETF") +')' )

try:
def check(ip,port):
link = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
link.connect((ip,int(port)))
link_ver = link.recv(12)
print(link_ver)

link.send(link_ver)
nb_sec_types = ord(link.recv(1))
print("types: " + str(nb_sec_types))

check(ips,"80")

如果有人知道如何使用列表中的 IP,那就太好了。

最佳答案

改变

check(ips, "80) 

对于

for ip in ips: 
check(ip, "80)

link.connect 需要一个唯一的 ip 并且您正在传递一个 ip 列表。

关于python - TypeError : str, 字节或字节数组预期,而不是列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49956156/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com