Good afternoon i will continue here my old post, I have a small problem, I have 2 different functions and then I can share them, but in my code what is happening is that one of these lines of code works, and the other doesn’t, and I really wanted to know why , because I wanted to insert a uuid in the cookies, but it didn’t, just another way, here it goes:
something like, this one works:
response.set_cookie('user_uuid', str(face_recognition.uuid))
but this one no response.set_cookie('user_uuid', str(cookie_uuid))
why ? no idea, they have the same value and the same name, one insert , and the other one no
the code that doesn’t work
def unique_identifier(request):
print("unique identifier function called...")
response = HttpResponse("Cookie Set")
cookie_uuid = uuid.uuid4() # Create a UUID
response.set_cookie('user_uuid', str(cookie_uuid))
print("UUID defined in the user's cookies:", cookie_uuid)
return response
debug:
No UUID found in user cookies
created a new UUID.
unique identifier function called...
UUID defined in user cookies: 5abb1b89-1ded-4fec-849d-567a9fb12d92
<django.contrib.sessions.backends.signed_cookies.SessionStore object at 0x000001A860C7BA50>
Session key: None
[22/May/2024 12:35:02] "GET / HTTP/1.1" 200 2373
the code that work
@csrf_exempt
def process_frame(request):
print("Processando frame...")
if request.method == 'POST':
frame_data = request.POST.get('frame_data')
frame_data = frame_data.split(',')[1] # Remover o prefixo 'data:image/png;base64,'
frame_data = base64.b64decode(frame_data)
frame_data = np.frombuffer(frame_data, dtype=np.uint8)
frame = cv2.imdecode(frame_data, flags=1)
cv2.imwrite('frames/CurrentFrame.jpg', frame)
# Agora você pode passar o frame para a função compare_faces()
result = compare_faces(request, frame)
print("result:", result)
if result == None:
response = JsonResponse({'error': 'Utilizador não encontrado crie um rosto'}, status=400)
elif isinstance(result, HttpResponseRedirect):
response = JsonResponse({'message': 'redirecionamento', 'url': result.url})
else:
response = JsonResponse({'message': result})
# Se um UUID foi gerado, defina-o no cookie da resposta
face_recognition = FaceRecognition(request)
if face_recognition.uuid is not None:
print("UUID gerado no processar frame:", face_recognition.uuid)
response.set_cookie('user_uuid', str(face_recognition.uuid))
print("Cookies definidos na resposta user_uuid:", response.cookies)
print("response:", response)
return response
else:
return JsonResponse({'message': 'Método não permitido'}, status=405)
debug
UUID gerado no processar frame: 9cfabec5-7409-421d-8e6b-f33f24eef7a5
Cookies definidos na resposta user_uuid: Set-Cookie: user_uuid=9cfabec5-7409-421d-8e6b-f33f24eef7a5; Path=/