【问题标题】:Issue accessing RapidAPI with httr / R - Status: 401使用 httr / R 访问 RapidAPI 时出现问题 - 状态:401
【发布时间】:2021-08-09 21:54:59
【问题描述】:

我正在尝试使用 R 中的 httr 包访问 RapidAPI,如下所示:

library(httr)
url <- "https://extract-news.p.rapidapi.com/v0/article"
queryString <- list(url = "https://www.theverge.com/2020/4/17/21224728/bill-gates-coronavirus-lies-5g-covid-19")
response <- VERB("GET", url, addheaders(x_rapidapi_key ="my-api-key", x_rapidapi_host = "extract-news.p.rapidapi.com"), query = queryString, contenttype("application/octet-stream"))
content(response, "text")

我也尝试访问其他 API。但是,我不断收到此错误消息:

Status: 401 

您能帮我解决这个问题吗? 提前非常感谢!

【问题讨论】:

标签: r http-status-code-401 httr rapidapi


【解决方案1】:

尝试使用content_type()add_headers 而不是contenttypeaddheaders 来告诉服务器您正在发送什么样的数据。阅读有关 VERB 方法的更多信息here

library(httr)

url <- "https://extract-news.p.rapidapi.com/v0/article"

queryString <- list(url = "https://www.theverge.com/2020/4/17/21224728/bill-gates-coronavirus-lies-5g-covid-19")

response <- VERB("GET", url, add_headers(x_rapidapi-host = 'extract-news.p.rapidapi.com', x_rapidapi-key = '*************************', '), query = queryString, content_type("application/octet-stream"))

content(response, "text")

【讨论】:

  • 嗨,我在R 上遇到了同样的问题,返回 401 消息。您发布的代码不起作用,有什么办法可以解决这个问题吗?非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-17
  • 1970-01-01
  • 2018-02-13
  • 2015-03-29
  • 2012-05-12
  • 2019-08-24
  • 1970-01-01
相关资源
最近更新 更多