【问题标题】:AzureCognitive R package translate service returns http 400: "body of request is not valid JSON."AzureCognitive R 包翻译服务返回 http 400:“请求正文不是有效的 JSON。”
【发布时间】:2021-12-24 00:21:11
【问题描述】:

我尝试使用 AzureCognitive R 包让翻译服务正常工作,但我收到 HTTP 400 错误,我似乎无法修复它。


# Initial setup
# I've already did the create login
# az <- AzureRMR::create_azure_login(tenant = "<tenant>")

az <- AzureRMR::get_azure_login()
sub <- az$get_subscription(id = "<id>")
rg <- sub$get_resource_group("<resource-group>")

# retrieve it
cogsvc <- rg$get_cognitive_service(name = "<name>")

# getting the endpoint from the resource object
endp <- cogsvc$get_endpoint()


############################
# This is where it fails
############################

call_cognitive_endpoint(endpoint = endp,
                        operation = "translate",
                        options = list('api-version' = "3.0",
                                       'from' = 'en',
                                       'to' = 'dk'),
                        body = "[{'Text':'Hello, what is your name?'}]",
                        http_verb = "POST")


call_cognitive_endpoint(endpoint = endp,
                        operation = "translate",
                        options = list('api-version' = "3.0",
                                       'from' = 'en',
                                       'to' = 'dk'),
                        body = list(text = "Hello, what is your name"),
                        http_verb = "POST")


谁能看看这是一个错误还是我做错了什么?

【问题讨论】:

标签: r azure azure-cognitive-services


【解决方案1】:

根据example,您可以将正文传递为body=list(list(text = "Hello, what is your name"")),

call_cognitive_endpoint(endpoint = endp,
                        operation = "translate",
                        options = list('api-version' = "3.0",
                                       'from' = 'en',
                                       'to' = 'dk'),
                        body = list(list(text = "Hello, what is your name")),
                        http_verb = "POST")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2014-09-11
    • 1970-01-01
    相关资源
    最近更新 更多