简体   繁体   English

使用 Ubuntu 20.04 LTS 中的 R download.file(“https://..”) 时出现“SSL 连接错误”

[英]'SSL connect error' when using R download.file(“https://..”) from Ubuntu 20.04 LTS

I am trying to obtain a zip from a https:// website:我正在尝试从 https:// 网站获取 zip:

url <- 'https://www150.statcan.gc.ca/n1/tbl/csv/23100008-eng.zip'
file_path <- './data/mydata.zip'
download.file(url, file_path)

I also have tried changing the method to 'curl', 'libcurl and 'get'我也尝试将方法更改为'curl', 'libcurl and 'get'

I 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'

My sessionInfo()我的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 

Oddly enough, the code runs perfectly in a Win OS but not in Ubuntu 20.04 LTS OS.奇怪的是,代码在 Win OS 中完美运行,但在 Ubuntu 20.04 LTS OS 中却没有。 I am not sure, but the issue seems to be a CA one which I have not been able to solve.我不确定,但问题似乎是我无法解决的 CA 问题。

From my terminal:从我的终端:

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

I tried using httr:我尝试使用 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

I also tried modifying the openssl.cnf , but I am still getting the same 'SSL connect error'我还尝试修改openssl.cnf ,但我仍然收到相同'SSL connect error'

Instructions to change the openssl.file:更改 openssl.file 的说明:

  1. Find where the openssl.cnf file is stored by running from your terminal:通过从终端运行查找 openssl.cnf 文件的存储位置:

    openssl version -d openssl版-d

  2. Run: sudo nano /usr/lib/ssl/openssl.cnf运行: sudo nano /usr/lib/ssl/openssl.cnf

  3. Modify the config file as follows: Add at the begining:修改配置文件如下: 在开头添加:

    openssl_conf = default_conf openssl_conf = default_conf

and at the end add:最后添加:

[ default_conf ]

ssl_conf = ssl_sect

[ssl_sect]

system_default = ssl_default_sect

[ssl_default_sect]
MinProtocol = TLSv1.2
CipherString = DEFAULT:@SECLEVEL=1

Next open RStudio:接下来打开 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

I also want to mention that these instructions helped me also to install the sf R package.我还想提一下,这些说明还帮助我安装了sf R package。

Thanks to Matt Caswell for his response .感谢 Matt Caswell 的回复 It would be neat to learn how to set up the path to point to another .cnf from RStudio (something similar to export OPENSSL_CONF=/home/Documents/new_openssl.cnf from terminal)学习如何设置从 RStudio 指向另一个.cnf的路径会很好(类似于export OPENSSL_CONF=/home/Documents/new_openssl.cnf from terminal)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM