[Answered ]-Process_request() takes exactly 2 arguments (1 given) – Django Basic HTTP Auth Decorator

1👍

remove self from process_request and pass request argument to func()

def basic_auth(func):

    def process_request(request):
        if request.META.get("HTTP_AUTHORIZATION"):
            encoded_auth =  request.META.get("HTTP_AUTHORIZATION")
            encoded_auth = encoded_auth[6:]
            auth = base64.b64decode(encoded_auth)
            auth_email = auth.split(":")[0]
            auth_password = auth.split(":")[1]
            if (auth_email == settings.BASIC_AUTH_EMAIL) and (auth_password == settings.EMAIL_HOST_PASSWORD):
                func(request)
            else:
                return HttpResponseForbidden("Forbidden")
    return process_request

for better understanding of function decorator:
http://thecodeship.com/patterns/guide-to-python-function-decorators/

1👍

You are not passing request as an argument to func(). Try with this:

if (auth_email == settings.BASIC_AUTH_EMAIL) and (auth_password == settings.EMAIL_HOST_PASSWORD):
    func(request)
else:
    return HttpResponseForbidden("Forbidden")

Leave a comment