我正在尝试制作一种可以访问照片并将它们与相机拍摄的照片进行比较的东西。它一直说“ PermissionError:[Errno 13]权限被拒绝:'C:\ Users \ monik \ Pictures'”。这是什么意思,为什么会拒绝?
代码:'''#!/ usr / bin / python导入base64,json,re将http.client导入为httplib从urllib导入解析#在您的MICROSOFT VISION API密钥下方更改{MS_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)
'''
C:\ Users \ monik \ Pictures是目录,因此无法打开它。您需要指向文件inside该目录。
body = open(r'C:\Users\monik\Pictures\img.jpeg', "rb").read()