cgi python windows_Windows上需要身份验证的Python CGI

在upd.你重写你的问题?在

cgi将http响应打印到stdout。

首先你需要得到标题。。。如果标题“Authorization”存在,您可以从中解码登录名和密码。

如果没有无效的标题或密码,您必须:

发送401响应

发送包含“Basic realm=\“Message\”的“WWW Authenticate”头进行基本授权。也可能是文摘,Ntlm等

如果浏览器得到401响应,它会要求用户输入密码(即使是ajax),用服务器要求的方法对登录名和密码进行编码,并用“Authorization”头再次发送请求。在

不是CGI代码示例,HTTPServer的decorator,BaseHTTPRequestHandlerdef 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值