You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R中jsonlite::fromJSON时遇'SSL connect error'如何解决?

解决办法

针对你遇到的jsonlite 1.8.2版本使用base::url()连接SEC服务器出现SSL错误的问题,可通过以下两种方式解决:

方法1:手动创建curl连接读取JSON

先确保curl包已安装(无需Rtools),然后手动建立curl连接再传给fromJSON():

# 若未安装curl包,先执行安装
install.packages("curl")
library(curl)

# 建立curl连接并读取数据
con <- curl("https://www.sec.gov/files/company_tickers_exchange.json")
all_companies <- jsonlite::fromJSON(con)
close(con)

方法2:设置全局选项强制jsonlite使用curl

通过修改jsonlite的全局配置,让其默认使用curl而非base::url():

# 设置全局选项,启用curl并设置超时时间
options(jsonlite.use_curl = TRUE, jsonlite.connect_timeout = 15)

# 直接运行原代码即可
all_companies <- jsonlite::fromJSON("https://www.sec.gov/files/company_tickers_exchange.json")

原理说明:旧电脑的jsonlite 1.8.0默认依赖curl连接,而1.8.2版本切换为base::url(),但你的新环境中base::url()无法和SEC服务器完成SSL握手,强制使用curl即可复用旧环境的有效连接逻辑。

内容的提问来源于stack exchange,提问作者Philli Phresh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 12:10:30