【问题标题】:R: cannot read API call - Error in open.connection(con, "rb")R:无法读取 API 调用 - open.connection 中的错误(con,“rb”)
【发布时间】:2021-11-13 01:11:31
【问题描述】:

我可以在 webbrowser 中看到 API 调用的内容,但是使用 jsonlite 包出现此错误:read_json

Error in open.connection(con, "rb") : connection cannot be opened
Añso: Warning message:
In open.connection(con, "rb") :
  cannot open URL 'https://www.plazavea.com.pe/api/catalog_system/pub/products/search?fq=C:/678/687/&_from=21&_to=41&O=OrderByScoreDESC&': HTTP status was '206 Partial Content'

代码:

library(rvest)
library(tidyverse)
library(jsonlite)



api_request <- "https://www.plazavea.com.pe/api/catalog_system/pub/products/search?fq=C:/678/687/&_from=21&_to=41&O=OrderByScoreDESC&"

product_data <- jsonlite::read_json(api_request)

【问题讨论】:

    标签: r json jsonlite


    【解决方案1】:

    使用 httr 然后提取 as = 'text' 并传递给 parse_json(),或者在响应对象上的 content() 调用中简单地指定 as = 'parsed'

    library(httr)
    
    api_request <- "https://www.plazavea.com.pe/api/catalog_system/pub/products/search?fq=C:/678/687/&_from=21&_to=41&O=OrderByScoreDESC&"
    
    product_data <- content(httr::GET(api_request), as = 'parsed')
    

    【讨论】:

    猜你喜欢
    • 2018-10-05
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    相关资源
    最近更新 更多