Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getpass.getpass error
#1
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'))
buran write Jan-21-2021, 06:51 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.

Also, always post in the correct forum. This time I moved your thread.
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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'))
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 755 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  getpass ComputerAstronaut 1 1,572 Nov-16-2020, 01:16 AM
Last Post: bowlofred
  Error "an integer is required" in getpass.getuser(). Nirelg 5 5,436 Mar-20-2017, 04:19 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020