Python Forum

Full Version: getpass.getpass error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys I'm getting this error when trying to run my code. Anyway someone could help me out. Thanks!
Bellow is the command line trying to run the run the code, and under that is the actual code.



Error:
root@NetworkAutomation-1:~# python3 getpass.py Enter your telnet username: tasha Traceback (most recent call last): File "getpass.py", line 3, in <module> import getpass File "/root/getpass.py", line 8, in <module> password = getpass.getpass() TypeError: 'module' object is not callable
import getpass
import telnetlib

HOST = "192.168.122.71"
user = input("Enter your telnet username: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"enable\n")
tn.write(b"mouse\n")
tn.write(b"conf t\n")
tn.write(b"int loop 0\n")
tn.write(b"ip address 1.1.1.1 255.255.255.255\n")
tn.write(b"end\n")
tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))
The problem is the name of your file - getpass.py it shadows the package getpass that you want to import and use getpass.getpass(). Rename your file.
Hey Braun thanks for the heads up. I'm new was kind of unsure how to use this. I had already previously changed the name and that did not work. I also just renamed it and still have an error. Any other ideas?





(Jan-21-2021, 06:49 PM)Juice1277 Wrote: [ -> ]Hey guys I'm getting this error when trying to run my code. Anyway someone could help me out. Thanks!
Bellow is the command line trying to run the run the code, and under that is the actual code.



Error:
root@NetworkAutomation-1:~# python3 getpass.py Enter your telnet username: tasha Traceback (most recent call last): File "getpass.py", line 3, in <module> import getpass File "/root/getpass.py", line 8, in <module> password = getpass.getpass() TypeError: 'module' object is not callable
import getpass
import telnetlib

HOST = "192.168.122.71"
user = input("Enter your telnet username: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"enable\n")
tn.write(b"mouse\n")
tn.write(b"conf t\n")
tn.write(b"int loop 0\n")
tn.write(b"ip address 1.1.1.1 255.255.255.255\n")
tn.write(b"end\n")
tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))
Hey Braun after making a cp of the old code into another file and actually deleting the getpass.py file. It WORKS! Thank you a whole lot