0

I am working on a django project with the face-recognition library, but I get this error:

Traceback (most recent call last):
...
  File "/.../site-packages/rest_framework/views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "/.../views.py", line 51, in post
    test_1              = face_recognition.load_image_file(path_)
  File "/.../site-packages/face_recognition/api.py", line 86, in load_image_file
    im = PIL.Image.open(file)
  File "/.../site-packages/PIL/Image.py", line 2878, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'http://127.0.0.1:8000/media/profile_pics/me.jpg'

This is what I have:

    req_user            = Profile.objects.all().filter(user__username=user_)
    req_img             = req_user.values('image')[0]['image'] #.partition("/")[2]
    path_               = 'http://127.0.0.1:8000/media/'+req_img

    test_1              = face_recognition.load_image_file(path_)
    test_1_enc          = face_recognition.face_encodings(test_1)[0]
    test_2              = face_recognition.load_image_file(newimage)
    test_2_enc          = face_recognition.face_encodings(test_2)[0]
    results             = face_recognition.compare_faces([test_1_enc],test_2_enc)
    if results[0]:
        print('Match')
    else:
        print('Please login with your password')

The image is located at path_

Thank you for any suggestions

Pypix
  • 71
  • 6

1 Answers1

0

It seems to be because you're trying to load the image from the internet rather than as a local file (even though it is being served from localhost).

See this answer How do I read image data from a URL in Python? to load an image in PIL from the internet.

g23
  • 666
  • 3
  • 9