You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hetzner部署应用访问www.fnde.gov.br出现连接超时问题求助

针对Hetzner服务器访问特定FNDE链接超时的解决方案

1. 排查目标站点的IP/路径限制

目标站点www.fnde.gov.br可能对Hetzner的IP段做了定向拦截——虽然其他路径能正常访问,但/distribuicaosimadnet/confirmarCancelar端点可能有额外的访问控制策略。

  • 尝试更换Hetzner服务器的IP(联系服务商申请)或通过代理服务器发起请求,验证是否能正常连接。
  • 用网络诊断工具排查路径问题:
    mtr --tcp --port 443 www.fnde.gov.br
    
    查看哪一跳出现丢包或延迟飙升,确认是网络节点故障还是目标端拦截。

2. 调整curl请求参数模拟浏览器行为

目标站点可能对请求头做了检测,Hetzner上默认的curl请求头可能被识别为非浏览器流量,导致超时。

  • 添加完整的浏览器请求头:
    curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" \
         -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" \
         -H "Accept-Language: en-US,en;q=0.5" \
         -H "Connection: keep-alive" \
         https://www.fnde.gov.br/distribuicaosimadnet/confirmarCancelar
    
  • 强制指定TLS版本并关闭缓存:
    curl --tlsv1.2 --no-cache https://www.fnde.gov.br/distribuicaosimadnet/confirmarCancelar
    

3. 检查Hetzner服务器本地网络配置

  • 临时关闭服务器防火墙(如ufw)测试是否有出站拦截:
    sudo ufw disable
    
    测试完成后重新开启:sudo ufw enable
  • 对比本地/AWS的DNS解析结果,若不一致则更换DNS服务器(如Cloudflare的1.1.1.1):
    echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf
    

4. Python代码层面优化

在Python请求中添加超时设置和重试机制,同时模拟浏览器请求头:

import requests
from tenacity import retry, stop_after_attempt, wait_exponential

@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=10))
def fetch_target_url():
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
    }
    response = requests.get(
        "https://www.fnde.gov.br/distribuicaosimadnet/confirmarCancelar",
        headers=headers,
        timeout=30
    )
    response.raise_for_status()
    return response.text

try:
    content = fetch_target_url()
    print(content)
except Exception as e:
    print(f"请求失败: {e}")

内容的提问来源于stack exchange,提问作者Wilson Nunes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 11:52:20