Python Forum
What is error: "TypeError: 'module' 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: What is error: "TypeError: 'module' object is not callable" (/thread-25999.html)



What is error: "TypeError: 'module' object is not callable" - phutran - Apr-18-2020

import getpass
import sys
import telnetlib
HOST = input("Enter device IP: ")
user = input("Enter your telnet user: ")
password = getpass.getpass()
tn = telnetlib(HOST)
tn.read("Username: ")
tn.write(user + "\n")
if password:
	tn.read_until("Password: ")
	tn.write(password + "\n")
tn.write("enable\n")
tn.write("cisco\n")
tn.write("config t\n")
tn.write("int loopback 0\n")
tn.write("ip address 1.1.1.1 255.255.255.255\n")
tn.write("end\n")
tn.write("exit\n")
print(tn.read())
Anyone help me this error:
Error:
Traceback (most recent call last): File "D:\NetworkAutomation\AssignIP.py", line 7, in <module> tn = telnetlib(HOST) TypeError: 'module' object is not callable
Thanks you so much.


RE: What is error: "TypeError: 'module' object is not callable" - Yoriz - Apr-18-2020

You need to call the Telnet class of the telnetlib module.
Change
tn = telnetlib(HOST)
to
tn = telnetlib.Telnet(HOST)



RE: What is error: "TypeError: 'module' object is not callable" - ndc85430 - Apr-18-2020

That's because you're trying to treat the module telnetlib like a function and it isn't, so you can't call it.


RE: What is error: "TypeError: 'module' object is not callable" - h1dd3n - May-12-2020

I'll explain what that error means.

When you call something that has () in it then it's a callable.
Whenever you call something ,it is initialized with __call__() method that is built in.
Your getting that error since the object you are calling doesn't have a built in __call__() method defined.