__init__.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:commissaire-http 作者: projectatomic 项目源码 文件源码
def decode_basic_auth(logger, http_auth):
    """
    Decodes basic auth from the header string.

    :param logger: logging instance
    :type logger: Logger
    :param http_auth: Basic authentication header
    :type http_auth: string
    :returns: tuple -- (username, passphrase) or (None, None) if empty.
    :rtype: tuple
    """
    if http_auth is not None:
        if http_auth.lower().startswith('basic '):
            try:
                decoded = tuple(base64.decodebytes(
                    http_auth[6:].encode('utf-8')).decode().split(':'))
                if logger:
                    logger.debug('Credentials given: %s', decoded)
                return decoded
            except base64.binascii.Error:
                if logger:
                    logger.info(
                        'Bad base64 data sent. Setting to no user/pass.')
    # Default meaning no user or password
    return (None, None)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号