Wget and SSL Issue

本文探讨了使用Wget时遇到的SSL连接问题,并详细记录了解决过程,包括升级OpenSSL版本、配置Wget等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Wget and SSL Issue

WGET issue:
>wget -nv -O ./2204.xml.gz 'https://xxxxx.com/feed.xml.gz'
OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Unable to establish SSL connection.

>openssl s_client -connect xxxxx.com:443 -debug
CONNECTED(00000003)
write to 0x2219f20 [0x22566f0] (249 bytes => 249 (0xF9))
0000 - 16 03 01 00 f4 01 00 00-f0 03 03 30 82 42 6c 52 ...........0.BlR
0010 - 89 2e 4d 14 26 64 6d b0-f2 a3 ac 0f 15 b3 99 7d ..M.&dm........}
0020 - 05 f7 74 76 25 fd 6d 1a-2b 68 14 00 00 84 c0 30 ..tv%.m.+h.....0
0030 - c0 2c c0 28 c0 24 c0 14-c0 0a 00 a3 00 9f 00 6b .,.(.$.........k
0040 - 00 6a 00 39 00 38 00 88-00 87 c0 32 c0 2e c0 2a .j.9.8.....2...*
0050 - c0 26 c0 0f c0 05 00 9d-00 3d 00 35 00 84 c0 2f .&.......=.5.../
0060 - c0 2b c0 27 c0 23 c0 13-c0 09 00 a2 00 9e 00 67 .+.'.#.........g
0070 - 00 40 00 33 00 32 00 9a-00 99 00 45 00 44 c0 31 .@.3.2.....E.D.1
0080 - c0 2d c0 29 c0 25 c0 0e-c0 04 00 9c 00 3c 00 2f .-.).%.......<./
0090 - 00 96 00 41 c0 12 c0 08-00 16 00 13 c0 0d c0 03 ...A............
00a0 - 00 0a 00 07 c0 11 c0 07-c0 0c c0 02 00 05 00 04 ................
00b0 - 00 ff 01 00 00 43 00 0b-00 04 03 00 01 02 00 0a .....C..........
00c0 - 00 0a 00 08 00 19 00 18-00 16 00 17 00 23 00 00 .............#..
00d0 - 00 0d 00 20 00 1e 06 01-06 02 06 03 05 01 05 02 ... ............
00e0 - 05 03 04 01 04 02 04 03-03 01 03 02 03 03 02 01 ................
00f0 - 02 02 02 03 00 0f 00 01-01 .........
read from 0x2219f20 [0x225bc50] (7 bytes => 7 (0x7))
0000 - 48 54 54 50 2f 31 2e HTTP/1.
140024920639328:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:795:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 249 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---


Rebuild Wget with Latest Version
>wget http://ftp.gnu.org/gnu/wget/wget-1.19.tar.gz

Exception:
configure: error: Package requirements (gnutls) were not met:
No package 'gnutls' found

Solution:
>sudo yum install gnutls
>./configure --with-ssl=openssl
>make clean
>./configure --prefix=/usr --with-ssl=openssl
make and make install to have the latest version

>wget -V
GNU Wget 1.19 built on linux-gnu.

-cares +digest -gpgme +https +ipv6 -iri +large-file -metalink +nls
+ntlm +opie -psl +ssl/openssl

OpenSSL version
>openssl version
OpenSSL 1.0.1k-fips 8 Jan 2015


On MAC the Exception is different
OpenSSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

>wget -V
GNU Wget 1.16 built on darwin14.3.0.
>openssl version
OpenSSL 0.9.8zh 14 Jan 2016

On CentOS the Exception
OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

>wget -V
GNU Wget 1.19 built on linux-gnu.
>openssl version
OpenSSL 1.0.1k-fips 8 Jan 2015

Let me first Work on the MAC
upgrade the openssl version to latest
>wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz
Unzip and directly make and make install

>openssl version
OpenSSL 1.1.0f 25 May 2017

Still have Exceptions
>openssl s_client -connect xxxx.com:443 -debug
CONNECTED(00000005)
write to 0x7f9f76e00340 [0x7f9f7800fe00] (176 bytes => 176 (0xB0))
0000 - 16 03 01 00 ab 01 00 00-a7 03 03 3b c9 85 56 3c ...........;..V<
0010 - ce 71 b8 ef a6 f9 ec 69-41 9e 96 85 04 72 5a ee .q.....iA....rZ.
0020 - 8f a3 6f 9b f5 a9 81 ba-8f 9a 9d 00 00 38 c0 2c ..o..........8.,
0030 - c0 30 00 9f cc a9 cc a8-cc aa c0 2b c0 2f 00 9e .0.........+./..
0040 - c0 24 c0 28 00 6b c0 23-c0 27 00 67 c0 0a c0 14 .$.(.k.#.'.g....
0050 - 00 39 c0 09 c0 13 00 33-00 9d 00 9c 00 3d 00 3c .9.....3.....=.<
0060 - 00 35 00 2f 00 ff 01 00-00 46 00 0b 00 04 03 00 .5./.....F......
0070 - 01 02 00 0a 00 0a 00 08-00 1d 00 17 00 19 00 18 ................
0080 - 00 23 00 00 00 0d 00 20-00 1e 06 01 06 02 06 03 .#..... ........
0090 - 05 01 05 02 05 03 04 01-04 02 04 03 03 01 03 02 ................
00a0 - 03 03 02 01 02 02 02 03-00 16 00 00 00 17 ..............
00b0 - <SPACES/NULS>
read from 0x7f9f76e00340 [0x7f9f78006a03] (5 bytes => 5 (0x5))
0000 - 48 54 54 50 2f HTTP/
140736693289920:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:ssl/record/ssl3_record.c:252:

It is not fixed on MAC.

Let me try On CentOS
Same issue, it does not fixed anything.

Get some information from my colleagues, maybe the file does not exist on the remote server or maybe the remote server is not well set up.

References:
https://help.directadmin.com/item.php?id=119
http://www.linuxfromscratch.org/blfs/view/svn/basicnet/wget.html
http://blog.techstacks.com/2010/03/3-common-causes-of-unknown-ssl-protocol-errors-with-curl.html
https://stackoverflow.com/questions/15166950/unable-to-establish-ssl-connection-how-do-i-fix-my-ssl-cert
http://ftp.gnu.org/gnu/wget/
http://mac-dev-env.patrickbougie.com/openssl/
### 如何在 PyCharm 中使用 `wget` 进行文件下载 为了能够在 PyCharm 中利用 `wget` 命令来执行文件下载操作,需确保环境已正确配置。对于 Windows 用户来说,可以通过 Git Bash 来实现这一目标。 #### 安装并配置 `wget` 如果是在 Windows 上工作,则需要先安装适用于该系统的 `wget` 工具: - 访问 [eternallybored](https://eternallybored.org/misc/wget/) 并依据所使用的操作系统版本挑选合适的二进制分发版。 - 将解压缩后的 `wget.exe` 文件放置于 Git 的路径下,比如 `\Git\mingw64\bin\` 目录内[^2]。 完成上述步骤之后,可以在命令提示符或 PowerShell 中验证 `wget` 是否可用,通过输入 `wget --version` 查看其版本号确认安装成功。 #### 使用 Python 调用 `subprocess` 执行 `wget` 下载任务 虽然可以直接调用 Shell 或者终端来进行文件下载,但在某些情况下更推荐的方式是从 Python 程序内部发起请求。下面是一个简单的例子展示怎样借助内置库 `subprocess` 实现这一点: ```python import subprocess def download_file(url, output_directory="."): try: result = subprocess.run( ["wget", "-P", output_directory, url], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) print(f"Download succeeded! {result.stdout.decode()}") except subprocess.CalledProcessError as e: error_message = f"There was an issue downloading the file: {e.stderr.decode()}" raise Exception(error_message) if __name__ == "__main__": target_url = "https://download-cdn.jetbrains.com/python/pycharm-community-2022.1.3.tar.gz" destination_folder = "./downloads/" # 创建保存位置的目录(如果不存在的话) import os if not os.path.exists(destination_folder): os.makedirs(destination_folder) download_file(target_url, destination_folder) ``` 这段脚本定义了一个名为 `download_file()` 函数用于接收 URL 和输出目录作为参数,并尝试从中获取资源到指定的位置。注意这里假设已经完成了前文中提到过的 `wget` 设置过程[^1]。 当遇到 SSL/TLS 证书验证失败的情况时,可以考虑添加 `--no-check-certificate` 参数绕过这个问题,但这通常只应用于测试环境中,在生产环境下应谨慎处理安全风险[^5]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值