背景
有个网站开了代理,浏览器可以访问,但是命令行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
- ProxyError: The application was unable to establish a connection to the proxy server.
- SSLError: The SSL/TLS handshake failed.
- SSLEOFError: The server abruptly closed the connection during the handshake, which is against the SSL protocol.
Common Causes
- Incorrect Proxy Configuration: The proxy settings (URL, port, username/password) might be incorrect.
- Incompatible SSL/TLS Version: The server or proxy might require a specific SSL/TLS version that is not supported or configured.
- Firewall or Network Issues: A firewall might be blocking the connection.
- Outdated SSL Certificates: The SSL certificates used by the client or proxy might be invalid or expired.
- Server-Side Issues: The proxy or server could be misconfigured or experiencing downtime.
Solutions
1. Verify Proxy Settings
- Double-check the proxy URL, port, and authentication credentials.
- Ensure the proxy server is reachable and functional by testing with tools like
curl
orping
.
2. Update SSL/TLS Configuration
- Explicitly configure your application to use a compatible SSL/TLS version.
- If you’re using Python’s
requests
library, you can set the SSL/TLS version using aSession
or a custom adapter.
3. Check Network and Firewall
- Ensure no firewalls or antivirus programs are blocking the connection.
- Use tools like
traceroute
ortelnet
to test the connection to the proxy server.
4. Update or Reinstall SSL Certificates
- Update your system’s CA certificates.
- If you’re working in a custom environment, use trusted certificate authorities.
5. Bypass Proxy (Temporary Test)
- Temporarily disable the proxy and test if the connection works directly.
6. Debugging Code Snippet
If you're using Python's requests
, consider this code to bypass or debug:
import requests
proxies = {
"http": "http://proxy-server:port",
"https": "http://proxy-server:port",
}
try:
response = requests.get("https://example.com", proxies=proxies, timeout=10)
print(response.status_code)
except requests.exceptions.ProxyError as e:
print(f"Proxy Error: {e}")
except requests.exceptions.SSLError as e:
print(f"SSL Error: {e}")
except Exception as e:
print(f"General Error: {e}")
7. Increase Logging
- Enable verbose logging for SSL and networking (e.g.,
requests
or your network library) to capture more details.
If the issue persists, provide more details about your environment, such as the programming language, library, and proxy setup, for more tailored assistance!
标签:UNEXPECTED,protocol,EOF,server,SSL,connection,proxy,http,requests From: https://www.cnblogs.com/lijiale/p/18612021