我已經遇到了另一個問題,下面給出的代碼我無法登錄,它仍然說訪問被拒絕,即使用戶名和密碼是正確的。控制檯上沒有錯誤。看起來我在連接後錯過了一些東西。python腳本的問題
我所要做的就是修改TODO部分,以便它在連接和成功登錄後對我的Oracle數據庫運行計算的查詢時,它應該顯示權限表的結果。
import cgi
import cx_Oracle
print("Content-type: text/html\n")
print("<title>Test</title>")
print("<body><center>")
try:
# get post data
form = cgi.FieldStorage()
name = form['name'].value if 'name' in form else ''
pwd = form['pwd'].value if 'pwd' in form else ''
permissions = []
# query to check password and get permissions
query = "SELECT PERMISSIONS FROM USERS WHERE NAME='{}' and PWD='{}'".format(name, pwd)
# TODO: connect to database and run query
host = '123.abc.com'
port = 1521
SID = 'orcl'
dsn_tns = cx_Oracle.makedsn(host, port, SID)
connection = cx_Oracle.connect('abuser', 'userpass', dsn_tns)
curs = connection.cursor()
result = curs.execute(query)
# TODO section ends
if len(permissions) > 0:
print("<H1>Access granted. You have the following permissions: {}.</H1>".format(permissions[0][0]))
else:
print("<H1>Access denied.</H1>")
connection.close()
except cx_Oracle.DatabaseError as e:
# for ease of debugging
print("Database Error: {}".format(e))
print("<br>Query: {}".format(query))
print("""
<form action="../login.html" method="GET">
<input type="submit" value="Back to Login">
</form>
""")
print('</center></body>')
我已經取消了您在編輯中刪除問題的位置。請不要破壞人們有禮貌地回答的問題。 – andrewsi