-1
我想從sqlite3數據庫中獲取數據,我知道返回元組使用cursor.fetchone()
但由於某種原因,當用戶在其它方案,這是一個CGI腳本提交數據,我把它並打印了2投其所好作爲他們的密碼,所以當我試圖比較他們,他們永遠不會匹配:2個元組相同時打印和unicode相同,但比較時,他們不匹配Python 2.7
#!/usr/bin/python
import sqlite3 as lite
import cgi
db = lite.connect('qwerty0987654321.db')
usrnme = "none"
passwd = "none"
passver = "none"
def main():
global usrnme
global passwd
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head><title>Profile</title></head>"
print "<body>"
form = cgi.FieldStorage()
if form.getvalue('username'):
usrnme = form.getvalue('username')
if form.getvalue('passwd'):
passwd = form.getvalue('passwd')
if isauth() is True:
print "Welcome %s" % usrnme
elif isauth() is False:
print "Wrong username or password!"
else:
print "No Password!"
else:
print "No Username!"
print '</body>'
print '</html>'
def isauth():
global usrnme, passwd, passver
c = db.cursor()
c.execute("SELECT password FROM Users WHERE username = ?",(usrnme,))
passver = c.fetchone()[0]
passver = tuple(passver,)
passwd = tuple(passwd[0],)
if cmp(passwd,passver) == 0:
return True
else:
print(passver,passwd)
return False
if __name__ == '__main__':
main()
那麼,什麼*是*打印呢?請向我們展示'print'語句的輸出。通常,CGI帖子無論如何都不會解碼爲「unicode」對象。 – 2014-12-07 02:19:06