def _get_basicauth_credentials(request):
authorization = AUTHORIZATION(request.environ)
try:
authmeth, auth = authorization.split(' ', 1)
except ValueError: # not enough values to unpack
return None
if authmeth.lower() == 'basic':
try:
auth = base64.b64decode(auth.strip().encode('ascii'))
except binascii.Error: # can't decode
return None
try:
login, password = auth.decode('utf8').split(':', 1)
except ValueError: # not enough values to unpack
return None
return {'login': login, 'password': password}
return None
评论列表
文章目录