Dzień dobry.
Dlaczego porównując dwa identyczne stringi, dostaję przy ich porównaniu False?
Wklejam kod:
from django.utils.deprecation import MiddlewareMixin
from django.http import HttpResponse
from django.conf import settings
import base64
class BasicAuthMiddleware(MiddlewareMixin):
def unauthed(self):
response = HttpResponse("""<html><title>Auth required</title><body>
<h1>Authorization Required</h1></body></html>""", content_type="text/html")
response['WWW-Authenticate'] = 'Basic realm="Development"'
response.status_code = 401
return response
def process_request(self,request):
if 'HTTP_AUTHORIZATION' not in request.META:
return self.unauthed()
else:
authentication = request.META['HTTP_AUTHORIZATION']
(authmeth, auth) = authentication.split(' ',1)
if 'basic' != authmeth.lower():
return self.unauthed()
auth = str(base64.b64decode(auth.strip()))
username, password = auth.split(':',1)
username = str(username)
password = str(password)
if username == settings.BASICAUTH_USERNAME and password == settings.BASICAUTH_PASSWORD:
print('OK')
return None
print('NOT OK', username == settings.BASICAUTH_USERNAME, password == settings.BASICAUTH_PASSWORD)
return self.unauthed()
Sprawdziłem, w pliku settings.py ustwaiłem stałe:
BASICAUTH_USERNAME = "myuser"
BASICAUTH_PASSWORD = "mypass"
dostaję print: print('NOT OK', username == settings.BASICAUTH_USERNAME, password == settings.BASICAUTH_PASSWORD):
NOT OK False False
What's going on?
PS. Dodam, że podaję identyczne stringi, wypisałem je w innym princie, co może być nie tak?