gpt4 book ai didi

r - 使用来自 Ubuntu 20.04 LTS 的 R download.file ("https://.."时出现“SSL 连接错误”

转载 作者:行者123 更新时间:2023-12-04 22:39:27 25 4
gpt4 key购买 nike

我正在尝试从 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 包。
    感谢 Matt Caswell 的 response .学习如何设置指向另一个 .cnf 的路径会很好。来自 RStudio(类似于 export OPENSSL_CONF=/home/Documents/new_openssl.cnf 来自终端)

    关于r - 使用来自 Ubuntu 20.04 LTS 的 R download.file ("https://.."时出现“SSL 连接错误”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62595675/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com