r - R - 错误404与API的人脸认知识别连接
问题描述
我想通过 R 连接微软人脸识别 API。但是,我得到了 404 错误。这是我的代码(修改自: https ://www.r-bloggers.com/analyze-face-emotions-with-r/ )
library(httr)
library("XML")
#guide from: https://www.r-bloggers.com/analyze-face-emotions-with-r/
faceURL <- 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0'
img.url <- 'https://images.pexels.com/photos/614810/pexels-photo-614810.jpeg?auto=compress&cs=tinysrgb&h=650&w=940'
#from: https://azure.microsoft.com/pl-pl/try/cognitive-services/my-apis/
faceKEY <- 'XXX'
# Define image
mybody = list(url = img.url)
# Request data from Microsoft
faceResponse = POST(
url = faceURL,
content_type('application/json'), add_headers(.headers = c('Ocp-Apim-Subscription-Key' = faceKEY)),
body = mybody,
encode = 'json'
)
# Show request results (if Status=200, request is okay)
faceResponse
#Outcome:
#Response [https://westcentralus.api.cognitive.microsoft.com/face/v1.0]
# Date: 2019-02-15 11:14
# Status: 404
# Content-Type: application/json
# Size: 113 B
#
# { "error": { "code": #"ResourceNotFound", "message": "The requested resource was not found." } }
我应该更正什么才能正确连接人脸识别 API?
解决方案
您收到的错误是 404 ( { "error": { "code": #"ResourceNotFound", "message": "The requested resource was not found." } }
),因此您应该查看您正在执行的请求。
实际上,您在这里尝试调用“ https://westcentralus.api.cognitive.microsoft.com/face/v1.0 ”
这是 API 的根目录,其中有多种方法,例如Detect
哪个 url 是“ https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect ”
在此处查看有关这些方法的更多详细信息:https ://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d
推荐阅读
- amazon-web-services - AWS Config 查询时间
- javascript - HTML/Js 中 RPG 字符表的某种计数器
- spring-boot - Spring boot中没有连接另一个配置文件
- javascript - 仅使用 jQuery/Ajax 刷新表的值而不重新加载页面
- html - 如何在 Wix 上为文件保留相同的链接
- google-cloud-platform - GCP - 动态获取云运行实例的 url
- scala - 火花提交命令
- database - Cassandra 上的事务“检查和插入”
- eclipse - E175002:服务器通过 VPN 拒绝连接
- azure - 参数和变量组选择 - YAML 管道