[英]'SSL connect error' when using R download.file(“https://..”) from Ubuntu 20.04 LTS
我正在嘗試從 https:// 網站獲取 zip:
url <- 'https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip'
file_path <- './data/mydata.zip'
download.file(url, file_path)
我也嘗試將方法更改為'curl', 'libcurl and 'get'
我得到:
trying URL 'https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip'
Error in download.file(url, file_path) :
cannot open URL 'https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip'
In addition: Warning message:
In download.file(url, file_path) :
URL 'https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip': status was 'SSL connect error'
我的sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8
[4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 lubridate_1.7.9 crayon_1.3.4 dplyr_1.0.0
[5] R6_2.4.1 lifecycle_0.2.0 magrittr_1.5 pillar_1.4.4
[9] httr_1.4.1 stringi_1.4.6 rlang_0.4.6 rstudioapi_0.11
[13] snakecase_0.11.0 vctrs_0.3.1 generics_0.0.2 ellipsis_0.3.1
[17] tools_4.0.2 stringr_1.4.0 glue_1.4.1 purrr_0.3.4
[21] janitor_2.0.1 compiler_4.0.2 pkgconfig_2.0.3 tidyselect_1.1.0
[25] tibble_3.0.1
奇怪的是,代碼在 Win OS 中完美運行,但在 Ubuntu 20.04 LTS OS 中卻沒有。 我不確定,但問題似乎是我無法解決的 CA 問題。
從我的終端:
openssl version -a
OpenSSL 1.1.1f 31 Mar 2020
built on: Mon Apr 20 11:53:50 2020 UTC
platform: debian-amd64
options: bn(64,64) rc4(16x,int) des(int) blowfish(ptr)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -Wa,--noexecstack -g -O2 -fdebug-prefix-map=/build/openssl-P_ODHM/openssl-1.1.1f=. -fstack-protector-strong -Wformat -Werror=format-security -DOPENSSL_TLS_SECURITY_LEVEL=2 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2
OPENSSLDIR: "/usr/lib/ssl"
ENGINESDIR: "/usr/lib/x86_64-linux-gnu/engines-1.1"
Seeding source: os-specific
我嘗試使用 httr:
library(httr)
set_config(config(ssl_verifypeer = FALSE))
httr::GET("https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip")
Error in curl::curl_fetch_memory(url, handle = handle) :
error:1414D172:SSL routines:tls12_check_peer_sigalg:wrong signature type
我還嘗試修改openssl.cnf ,但我仍然收到相同'SSL connect error'
更改 openssl.file 的說明:
通過從終端運行查找 openssl.cnf 文件的存儲位置:
openssl版-d
運行: sudo nano /usr/lib/ssl/openssl.cnf
修改配置文件如下: 在開頭添加:
openssl_conf = default_conf
最后添加:
[ default_conf ]
ssl_conf = ssl_sect
[ssl_sect]
system_default = ssl_default_sect
[ssl_default_sect]
MinProtocol = TLSv1.2
CipherString = DEFAULT:@SECLEVEL=1
接下來打開 RStudio:
file_path <- './data/raw/nmvs_data.zip'
url <- 'https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip'
download.file(url, file_path)
trying URL 'https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip'
Content type 'application/zip' length 3103330 bytes (3.0 MB)
==================================================
downloaded 3.0 MB
我還想提一下,這些說明還幫助我安裝了sf
R package。
感謝 Matt Caswell 的回復。 學習如何設置從 RStudio 指向另一個.cnf
的路徑會很好(類似於export OPENSSL_CONF=/home/Documents/new_openssl.cnf
from terminal)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.