Systematic workflow for troubleshooting SSL/proxy connectivity issues with government websites
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-ssl-proxy-troubleshoot-2687e6fe1636 ,按照其中的说明把「ssl-proxy-troubleshoot」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill provides a systematic approach to diagnosing and resolving SSL certificate and proxy connectivity issues when accessing government websites, which often have stricter security configurations than commercial sites.
First, identify what type of connectivity problem you're facing:
import requests
import ssl
url = "https://example.gov/data"
# Test basic connectivity
try:
response = requests.get(url, timeout=10)
print(f"Status: {response.status_code}")
except requests.exceptions.SSLError as e:
print(f"SSL Error: {e}")
except requests.exceptions.ProxyError as e:
print(f"Proxy Error: {e}")
except requests.exceptions.ConnectionError as e:
print(f"Connection Error: {e}")
except Exception as e:
print(f"Other Error: {e}")
Government sites sometimes have misconfigured redirects or support only specific protocols:
urls_to_try = [
"https://example.gov/data",
"http://example.gov/data", # Try unencrypted
"https://www.example.gov/data", # Try www subdomain
"http://www.example.gov/data",
]
for url in urls_to_try:
try:
response = requests.get(url, timeout=10, verify=False)
if response.status_code == 200:
print(f"Success with: {url}")
break
except Exception as e:
print(f"Failed {url}: {e}")
Only use this for debugging. If it works, the issue is SSL certificate-related:
# Option A: Disable verification entirely (debug only)
response = requests.get(url, verify=False, timeout=30)
# Option B: Use custom SSL context with relaxed settings
import ssl
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
response = requests.get(url, verify=False, timeout=30)
Warning: Never use verify=False in production. If this is the only working option, document the SSL issue and seek alternative data sources.
Government networks often require specific proxy configurations:
# Option A: Disable proxy entirely
session = requests.Session()
session.trust_env = False # Ignore environment proxy settings
response = session.get(url, timeout=30)
# Option B: Explicitly set proxy
proxies = {
"http": "http://proxy.example.com:8080",
"https": "http://proxy.example.com:8080",
}
response = requests.get(url, proxies=proxies, timeout=30, verify=False)
# Option C: Try without any proxy configuration
import os
os.environ.pop("HTTP_PROXY", None)
os.environ.pop("HTTPS_PROXY", None)
os.environ.pop("http_proxy", None)
os.environ.pop("https_proxy", None)
response = requests.get(url, timeout=30)
Government data is often mirrored or available through alternative access points:
# Common alternative patterns for government sites
alternative_urls = [
url.replace(".gov", ".gov.uk"), # Regional variations
url.replace("data.", "api."), # API subdomain
url.replace("https://", "https://archive."), # Archive mirror
url.replace("/data", "/download"), # Alternative path
]
# Check for data.gov or similar portals
portal_search = f"site:data.gov {topic_keyword}"
Some clients handle SSL/proxy differently:
# Try urllib instead of requests
import urllib.request
import ssl
ssl_context = ssl._create_unverified_context()
response = urllib.request.urlopen(url, context=ssl_context, timeout=30)
# Try curl via subprocess
import subprocess
result = subprocess.run(
["curl", "-k", "-L", "--max-time", "30", url],
capture_output=True,
text=True
)
When all troubleshooting attempts fail after 5-10 iterations:
# Search for the same data from different sources
search_queries = [
f"{dataset_name} site:epa.gov",
f"{dataset_name} site:data.gov",
f"{dataset_name} state database",
f"{dataset_name} public download",
]
# Try Wayback Machine
wayback_url = f"https://web.archive.org/web/*/{original_url}"
# Check for cached versions
# Try Google Cache: http://webcache.googleusercontent.com/search?q=cache:{url}
Many government datasets have REST APIs even when web interfaces fail:
# Common API patterns
api_endpoints = [
url.replace("/portal", "/api"),
url + "/api/v1/data",
url + "/rest/data",
]
If data is critical and unavailable:
| Issue Type | Symptom | Recommended Action |
|---|---|---|
| SSL Certificate | SSLError, CERT_VERIFY_FAILED | Try verify=False for debug, then find alternative source |
| Proxy Blocking | ProxyError, Connection refused | Set trust_env=False, try direct connection |
| Timeout | ReadTimeout, ConnectTimeout | Increase timeout, try different client |
| 403/401 Errors | HTTP status errors | Check for required headers, authentication |
| DNS Failure | Name resolution error | Try IP address directly, check alternative domains |
verify=False is required, flag this as a security concerndef robust_government_request(url, max_attempts=5):
"""Attempt to fetch government URL with multiple fallback strategies."""
strategies = [
{"verify": True, "trust_env": True, "timeout": 30},
{"verify": False, "trust_env": True, "timeout": 30},
{"verify": False, "trust_env": False, "timeout": 30},
{"verify": False, "trust_env": False, "timeout": 60},
]
for i, config in enumerate(strategies[:max_attempts]):
try:
session = requests.Session()
session.trust_env = config["trust_env"]
response = session.get(
url,
verify=config["verify"],
timeout=config["timeout"]
)
if response.status_code == 200:
return response
except Exception as e:
print(f"Attempt {i+1} failed: {e}")
continue
return None # All strategies failed