fak3
fak3

Reputation: 3

Python SocketModule: 'str' object has no attribute 'connect'

I'm probably being really dumb but I can't resolve this error in a basic client script.

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()

"Attribute Error: 'str' object has no attribute 'connect'

Upvotes: 0

Views: 1428

Answers (2)

rafaelc
rafaelc

Reputation: 59274

You defined

def otherclient(desipaddr, myclient, desport):

But passed

otherclient(myclient, desipaddr, desport)

Upvotes: 1

Kurt Stutsman
Kurt Stutsman

Reputation: 4034

You have the arguments to otherclient(myclient, desipaddr, desport) reversed according to the function definition.

Upvotes: 1

Related Questions