Precisava de uma ajuda com os formulários em cgi no python.
Este código funciona normalmente quando não insiro acentos:
# !/Programas/Python36-32/python # -*- coding: utf-8 -*- import cgi print("Content-Type: text/html; UTF-8\n") form = cgi.FieldStorage() web_page=""" <!DOCTYPE HTML> <html> <head> <title>O Meu primeiro programa</title> </head> <body> <form method="post"> Name: <input type="text" name="name"><br> Password: <input type="text" name="password"><br> <input type="submit" value="Submit"> </form> </body> </html> """ print(web_page) name=form["name"].value password=form["password"].value print("name: "+name) print("<br>") print("password: "+password) with open("file.txt", "w") as f: f.write("name: "+name+"\n"+"password: "+password)
Mas simplesmente não escreve nada no ficheiro quando eu coloco acentos. Alguém me pode ajudar a gravar os dados dos campos num ficheiro?
Nota: Eu uso o servidor XAMPP, versão 3.2.2 com o apache versão 2.4.29