r - R:无法读取 API 调用 - open.connection 中的错误(con,“rb”)
问题描述
我可以在 webbrowser 中看到 API 调用的内容,但是使用jsonlite
package:得到这个错误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)
解决方案
使用 httr 然后提取as = 'text'
并传递给parse_json()
,或者简单地在响应对象as = 'parsed'
的调用中指定。content()
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')
推荐阅读
- python - 将二维数组中的每个值乘以另一个二维数组中的对应值
- javascript - 通过 Chrome 扩展在新标签页加载上查询域
- r - 在 R 中生成可能的序列
- java - 如何返回递归添加的树的根?
- node.js - 如何使用 IIS 重定向向另一个端口中的节点发送请求
- powershell - 如何使用 Invoke-WmiMethod 将调试器附加到进程?
- python - 将 C++ boost::variant 暴露给 Python 时出错
- c++ - 初始化器列表中的复制构造
- python - 使用 Flask 对 POST 表单请求进行错误请求
- php - 当我安装作曲家并使用自动加载选项时,路由不起作用?