Caused by ProxyError(‘Unable to connect to proxy‘, SSLError(SSLEOFError(8, ‘[SSL: UNEXPECTED_EOF_WHI

背景

有个网站开了代理,浏览器可以访问,但是命令行ping不通,telnet不通,python requests请求报上述错误

解决方案

配置代理,改成http请求

url = "http://m.zhibo8.com/news/web/zuqiu/2024-12-02/match1437755date2024vnative.htm"  # 替换为实际的网页链接

proxies = {
    'http': 'http://127.0.0.1:7890',
    # 'https': 'https://127.0.0.1:7890'
}

# 发送请求并获取网页内容
response = requests.get(url, proxies=proxies, verify=False)

参考

This error is related to an issue with SSL while attempting to connect to a server through a proxy. Here’s a breakdown of the problem and possible solutions:

Problem Details

  1. ProxyError: The application was unable to establish a connection to the proxy server.
  2. SSLError: The SSL/TLS handshake failed.
  3. SSLEOFError: The server abruptly closed the connection during the handshake, which is against the SSL protocol.

Common Causes

  1. Incorrect Proxy Configuration: The proxy settings (URL, port, username/password) might be incorrect.
  2. Incompatible SSL/TLS Version: The server or proxy might require a specific SSL/TLS version that is not supported or confi
你遇到的错误: ``` elastic_transport.TlsError: TLS error caused by: TlsError(TLS error caused by: SSLError([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992))) ``` 是由于 Elasticsearch 客户端在尝试通过 HTTPS 连接时,无法验证服务器的 SSL 证书。这通常发生在使用自签名证书或证书链不完整的情况下。 --- ### 解决方案 #### ✅ 方法一:指定 CA 证书路径(推荐) 如果你有服务器使用的 CA 证书文件(例如 `ca.crt`),可以在连接时指定该证书路径以完成验证。 ```python from elasticsearch import Elasticsearch es = Elasticsearch( ["https://10.6.2.149:9200"], basic_auth=("elastic", "234"), ca_certs="/path/to/ca.crt" # 指定 CA 证书路径 ) ``` #### ✅ 方法二:禁用 SSL 验证(不推荐用于生产) 如果你在测试环境中,并且不关心 SSL 验证,可以禁用 SSL 验证(不建议在生产中使用): ```python from elasticsearch import Elasticsearch es = Elasticsearch( ["https://10.6.2.149:9200"], basic_auth=("elastic", "234"), verify_certs=False, ssl_show_warn=False # 可选:关闭警告 ) ``` > ⚠️ 注意:禁用 SSL 验证存在安全风险,可能会导致中间人攻击。 #### ✅ 方法三:忽略证书验证(使用 `request_timeout` 和 `timeout`) 有时也可以通过设置 `use_ssl` 和 `verify_certs` 来忽略证书验证(效果同上): ```python es = Elasticsearch( ["https://10.6.2.149:9200"], basic_auth=("elastic", "234"), verify_certs=False ) ``` --- ### 小结: | 方法 | 是否安全 | 说明 | |------|----------|------| | 指定 `ca_certs` | ✅ 安全 | 推荐方式,用于生产环境 | | 设置 `verify_certs=False` | ❌ 不安全 | 仅用于测试环境 | | 使用 `ssl_show_warn=False` | ✅ 安全 | 可选,用于隐藏警告信息 | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值