我的英語很差。我很抱歉。需要身份驗證 - Windows Server上的Python CGI
我用plesk面板購買了Wİndows服務器。 我加載到FTP python腳本。因爲該網站是用python編寫的。
當我進入該網站時,我看到「需要驗證」。但我想看看這個窗口。我希望每個人都可以進入該網站並運行到cgi腳本。
我該如何做到這一點?
我的英語很差。我很抱歉。需要身份驗證 - Windows Server上的Python CGI
我用plesk面板購買了Wİndows服務器。 我加載到FTP python腳本。因爲該網站是用python編寫的。
當我進入該網站時,我看到「需要驗證」。但我想看看這個窗口。我希望每個人都可以進入該網站並運行到cgi腳本。
我該如何做到這一點?
upd.you改寫你的問題?
cgi打印http響應標準輸出。 首先,您需要獲取標題......如果標題「授權」存在,您可以從中解碼登錄名和密碼。 如果沒有這樣的頭文件或passord無效,您必須: 發送401響應 發送包含'Basic realm = \'Message''的'WWW-Authenticate'標頭用於基本授權。也可能Digest,Ntlm等
如果瀏覽器得到401響應,它要求用戶輸入密碼(即使ajax),用服務器請求的方法編碼登錄名和密碼,再用'授權'標頭髮送請求。
不是CGI代碼示例,裝飾商的HttpServer,BaseHTTPRequestHandler
def login_required(f):
def authenticate(self,*args,**kwargs):
if conf.get('noauth'):
return f(self,*args,**kwargs)
if self.headers.getheader('Authorization') :
cred = base64.b64decode(self.headers.getheader('Authorization').split(' ')[1])
users = conf.get('users', [])
if cred in users:
self.creds = cred
return f(self,*args,**kwargs)
#else
self.send_response(401)
self.send_header('WWW-Authenticate', 'Basic realm=\"Meter\"')
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write('Not authenticated.')
return False
return authenticate
謝謝。我會嘗試 – user1898723
很抱歉,但我不明白。 –