0

I am trying to make a thing that accesses photos and compares them with a photo taken by a camera. It keeps saying PermissionError: [Errno 13] Permission denied: 'C:\\Users\\monik\\Pictures'. What does that mean and why is the permission denied?

The code:

    #!/usr/bin/python
    import base64, json, re
    import http.client as httplib
    from urllib import parse
    # CHANGE {MS_API_KEY} BELOW WITH YOUR MICROSOFT VISION API KEY
    ms_api_key = "{MS_API_KEY}"

    # setup vision API
    headers = {
        'Content-Type': 'application/octet-stream',
        'Ocp-Apim-Subscription-Key': ms_api_key,
    }
    params = parse.urlencode({
        'visualFeatures': 'Description',
    })

    # read image
    body = open(r'C:\Users\monik\Pictures', "rb").read()

    # submit request to API and print description if successful or error otherwise
    try:
        conn = HTTPSConnection('westcentralus.api.cognitive.microsoft.com')
        conn.request("POST", "/vision/v1.0/analyze?%s"%params, body, headers)
        response = conn.getresponse()
        analysis=json.loads(response.read())
        image_caption = analysis["description"]["captions"][0]["text"].capitalize()
        conn.close()
        print (image_caption)

    except Exception as e:
        print (e.args)
emporerblk
  • 1,063
  • 5
  • 20
  • Does this answer your question? [PermissionError: \[Errno 13\] in python](https://stackoverflow.com/questions/13207450/permissionerror-errno-13-in-python) – emporerblk May 17 '20 at 23:33

1 Answers1

1

C:\Users\monik\Pictures is a directory, so you cannot open it. You'd need to point at a file inside that directory.

body = open(r'C:\Users\monik\Pictures\img.jpeg', "rb").read()
emporerblk
  • 1,063
  • 5
  • 20