'str' object is not callable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: 'str' object is not callable (/thread-534.html) Pages:
1
2
|
'str' object is not callable - peterkl - Oct-17-2016 Hello guys, I'm trying to build a simple port scanner, but I constantly got this error : ''str' object is not callable" I really don't know why I'm getting it, I did not assign a var as str, e.g : str= 'hello'. I tried to review my script quite few times now, I looked the problem up on the web, still nothing. Thank you for your help. (P.S : just had to create a brand new account, cuz the forum moved and I wasn't able to login anymore, or recuperate my password) from socket import * def port_scanner(host,port): socket = ' ' try: socket = socket(AF_INET,SOCK_STREAM) socket.connect(host,int(port)) # tried to double the parentheses here, still did not work result = '[>]'+host+' :is opened on:'+str(port) print result except Exception,e: print e print '[!]'+host+' is not opened on'+str(port) def main(): totalchars = 0 totalpoints = 0 listofports = ['80','21','22'] host = gethostbyname('www.xxxx.com') for char in host: totalchars = 1+totalchars if char == '.': totalpoints = 1+totalpoints if totalpoints == 3: hostfixed = host[:totalchars] for num in range(1,255): num1 = str(num) host1 = hostfixed+num1#I've also tried ...+str(num) and it does not work. for port in listofports: port_scanner(host1,port) main() RE: 'str' object is not callable - demosthenesk - Oct-17-2016 try host1 = str(hostfixed)+str(num1) RE: 'str' object is not callable - peterkl - Oct-17-2016 (Oct-17-2016, 05:36 PM)demosthenesk Wrote: try Did not work, m8 :( thank you anyway :) RE: 'str' object is not callable - Yoriz - Oct-17-2016 When posting an error, please posts the full traceback error in error tags. Temporarily remove/comment out the try/except clause to get the full traceback error to show. RE: 'str' object is not callable - peterkl - Oct-17-2016 (Oct-17-2016, 05:47 PM)Yoriz Wrote: When posting an error, please posts the full traceback error in error tags. That's the full traceback error :)
RE: 'str' object is not callable - Yoriz - Oct-17-2016 That is not the full traceback error, its doesn't show the line number the error occurred, the line that caused the error and what lead up to the error. That's the result of a catch all exception. Temporarily remove/comment out the try/except clause to get the full traceback error to show. RE: 'str' object is not callable - micseydel - Oct-17-2016 That's not a traceback. How are you running your code? We need to know the line number the problem is occurring on. By the way, the code you posted looks like it'd have an indentation error before being able to have a TypeError (as I suspect you are experiencing; it's hard to know for certain without the traceback). RE: 'str' object is not callable - peterkl - Oct-17-2016 (Oct-17-2016, 05:59 PM)Yoriz Wrote: That is not the full traceback error, its doesn't show the line number the error occurred, the line that caused the error and what lead up to the error. You're right, sorry for that.
(Oct-17-2016, 06:01 PM)micseydel Wrote: That's not a traceback. How are you running your code? We need to know the line number the problem is occurring on. It got indentation problems while I copied it. I'll fix the code on my post now. With the traceback I was able to solve the problem my self. Completely forgot to fully checked the traceback and not only the Exception msg. Since the error was on the line 7 , socket = socket(AF_INET,SOCK_STREAM), i changed it to : socketkl = socket(AF_INET,SOCK_STREAM) and it worked fine. I'm not able to explain why, but I think it's because I was calling the function "socket" from the lib socket twice : here 'socket =' and here ' socket(AF_INET....)' ; thank you for your patient, I will make more attention in indentation next time, as well as posting the traceback and not only the exception msg. RE: 'str' object is not callable - Yoriz - Oct-17-2016 You have over written the imported socket. from socket import * def port_scanner(host,port): socket = ' ' RE: 'str' object is not callable - peterkl - Oct-17-2016 (Oct-17-2016, 06:30 PM)Yoriz Wrote: You have over written the imported socket. Thank you :) |