Python SocketModule: 'str' 对象没有属性 'connect'
Python SocketModule: 'str' object has no attribute 'connect'
我可能真的很笨,但我无法在基本客户端脚本中解决此错误。
import socket
ipaddr = ""
desipaddr = ""
desport = 9999
myclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def startclient(desipaddr):
desipadd = raw_input("[+] Enter chatserver IP: ")
desipaddr = str(desipadd)
return desipaddr
def otherclient(desipaddr, myclient, desport):
myclient.connect(desipaddr, desport)
datatosend = raw_input("[+]>>> ")
myclient.send(datatosend)
datatoberecv = myclient.recv(1024)
formatteddata = "[+] " + str(datatoberecv)
print formatteddata
def main():
startclient(desipaddr)
otherclient(myclient, desipaddr, desport)
main()
"属性错误: 'str' 对象没有属性 'connect'
您已根据函数定义反转 otherclient(myclient, desipaddr, desport)
的参数。
您定义了
def otherclient(desipaddr, myclient, desport):
但是通过了
otherclient(myclient, desipaddr, desport)
我可能真的很笨,但我无法在基本客户端脚本中解决此错误。
import socket
ipaddr = ""
desipaddr = ""
desport = 9999
myclient = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def startclient(desipaddr):
desipadd = raw_input("[+] Enter chatserver IP: ")
desipaddr = str(desipadd)
return desipaddr
def otherclient(desipaddr, myclient, desport):
myclient.connect(desipaddr, desport)
datatosend = raw_input("[+]>>> ")
myclient.send(datatosend)
datatoberecv = myclient.recv(1024)
formatteddata = "[+] " + str(datatoberecv)
print formatteddata
def main():
startclient(desipaddr)
otherclient(myclient, desipaddr, desport)
main()
"属性错误: 'str' 对象没有属性 'connect'
您已根据函数定义反转 otherclient(myclient, desipaddr, desport)
的参数。
您定义了
def otherclient(desipaddr, myclient, desport):
但是通过了
otherclient(myclient, desipaddr, desport)