Forum >> Principianti >> File e TypeError

Pagina: 1

Ciao a tutti.

Ho creato un programma che simula un specie di terminale nel quale, dato un certo comando, parte un questionario in inglese con domande personali. Dopo aver avuto quelle risposte, il progranna dovrebbe creare un file con dentro queste info.


Ecco il codice:

import time
pwfinder = "pwfinder"

class bcolors:
	HEADER = '\033[95m'
	OKBLUE = '\033[94m'
	OKGREEN = '\033[92m'
	WARNING = '\033[93m'
	FAIL = '\033[91m'
	ENDC = '\033[0m'
	BOLD = '\033[1m'
	UNDERLINE = '\033[4m'


print(bcolors.HEADER + "ceated by @lucagamerro")
time.sleep(0.5)
print(bcolors.HEADER + "inspired to MrRobot")
time.sleep(0.5)
print(bcolors.HEADER + "type pwfinder to start the simulation")
time.sleep(0.5)
print(bcolors.HEADER + " ")
print("\n" * 16)
time.sleep(5.0)

time.sleep(0.5)

def pwfinder():
    print(bcolors.HEADER + "pwfinder, V 13.1, created by @lucagamerro")
    print("complete this survey for generate a customized wordlist")
    print("\n" *3)
    name = input(bcolors.OKGREEN + "Name: ")  
    surname = input(bcolors.OKGREEN + "Surname: ") 
    pet = input(bcolors.OKGREEN + "Pet's name: ") 
    wh = input(bcolors.OKGREEN + "Wife's or Husband's name: ")  
    bth = input(bcolors.OKGREEN + "Birthday: ") 
    n = input(bcolors.OKGREEN + "Favourite Numbers: ")
    son1 = input(bcolors.OKGREEN + "Son-1's name: ")  
    son2 = input(bcolors.OKGREEN + "Son-2's name: ") 
    info = input(bcolors.OKGREEN + "Other info: ")
    time.sleep(0.2)
    print(bcolors.OKBLUE + "...GENERATING PASSWORD...")
    time.sleep(6) 
    out_file = open("/home/luke/Scrivania/pwfinder_wordlist.txt", "w")
    time.sleep(0.5)
    out_file.write(name)
    time.sleep(1)
    out_file.write(name, surname)
    time.sleep(1)
    out_file.write(name, bth)
    time.sleep(1)
    out_file.write(name, info)
    time.sleep(1)
    out_file.write(name, ".", surname)
    time.sleep(1)
    out_file.write(name, ".", bth)
    time.sleep(1)
    out_file.write(name, n)
    time.sleep(1)
    out_file.write(name, ".", n)
    time.sleep(1)
    out_file.write(name, wh)
    time.sleep(1)
    out_file.write(surname, name)
    time.sleep(1)
    out_file.write(surname, ".", name)
    time.sleep(1)
    out_file.close()
    print("password saved at pwfinder_wordlist.txt ")
    exit()

def terminal():
    z = bcolors.OKBLUE + "root@elliot:# "
    try:
       x = input(z + bcolors.OKGREEN + " ")
    except NameError:
       print(bcolors.WARNING + "command not found...")
       print("\n")
       exit()
    try:
       if x == pwfinder:
          pwfinder()
    except NameError:
       print("Anythings don't work...")
       print(bcolors.ENDC + "
  • exit
  • ")
    time.sleep(3)
    exit()
    try:
    terminal()
    except KeyboardInterrupt:
    print("\n" * 20)
    print(bcolors.ENDC + "
  • exit
  • ")
    time.sleep(3)
    exit() Ho lanciato il programma da amministratore (sono su Linux Ubuntu) e andava tuttto bene finche alla fine del questionario mi ha dato questo errore:

    Traceback (most recent call last):
      File "elliot.py", line 88, in <module>
        terminal()
      File "elliot.py", line 81, in terminal
        pwfinder()
      File "elliot.py", line 45, in pwfinder
        out_file.write(name)
    TypeError: expected a string or other character buffer object
    root@luke-LIFEBOOK-A544:/home/luke/Scrivania# 
    
    
    Il file lo crea ma non c'e scritto nulla :confused:




    Grazie :py:



    --- Ultima modifica di luke in data 2019-01-04 12:41:44 ---
~luke
Tiro a indovinare. Perché stai usando (ancora!) python 2.
https://leanpub.com/capirewxpython: Capire wxPython, il mio libro
https://pythoninwindows.blogspot.com: Python in Windows, il mio blog e le mie guide
Ho installato python 3.4 ma quando lo faccio partire mi parte python 2.7

Come faccio a far in modo che utilizzi l'ultima versione?

~luke
Dici "python3" al prompt della shell (se ricordo, su ubuntu). O guardi dov'è l'eseguibile e ti crei un alias. O fai le tipiche cose che si fanno su linux con la shell, non so.
https://leanpub.com/capirewxpython: Capire wxPython, il mio libro
https://pythoninwindows.blogspot.com: Python in Windows, il mio blog e le mie guide
Ho avviato il file con python 3.7, ma appena digito "pwfinder" esce e basta.

Senza dare errori. La stessa cosa mi capita se provo su Windows.

Che posso fare?!? :confused:

~luke


Pagina: 1



Esegui il login per scrivere una risposta.