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

无法连接encompasshealth.com:443 ssl:default [None] 技术求助

解决pysitemap爬虫SSL连接失败问题

针对你遇到的Cannot connect to host encompasshealth.com:443 ssl:default [None]错误,可按以下步骤排查解决:

1. 验证网络可访问性

先手动在浏览器打开目标链接https://encompasshealth.com/concordrehab,确认能正常加载页面:

  • 如果无法访问,说明是网络限制(比如防火墙、地区封锁),需切换网络环境或配置代理。
  • 如果可以访问,再继续排查代码和环境问题。

2. 更新CA证书库

本地CA证书过期或缺失会导致SSL验证失败,执行以下命令更新certifi库:

pip install --upgrade certifi

3. 配置代理(如果需要)

如果你的网络需要代理才能访问目标网站,可通过修改pysitemap的client配置,传入aiohttp的代理参数。修改代码如下:

import sys
import logging
from pysitemap import crawler
import aiohttp

if __name__ == '__main__':
    if '--iocp' in sys.argv:
        from asyncio import events, windows_events
        sys.argv.remove('--iocp')
        logging.info('using iocp')
        el = windows_events.ProactorEventLoop()
        events.set_event_loop(el)
 
    root_url = 'https://encompasshealth.com/concordrehab'
    # 配置代理,替换成你的代理地址和端口
    connector = aiohttp.TCPConnector(proxy="http://your-proxy-address:port")
    crawler(root_url, out_file='sitemap.xml', client_config={'connector': connector})

4. 临时跳过SSL验证(仅测试用)

如果只是临时测试,可关闭SSL验证(生产环境禁止使用,存在安全风险),修改代码如下:

import sys
import logging
from pysitemap import crawler

if __name__ == '__main__':
    if '--iocp' in sys.argv:
        from asyncio import events, windows_events
        sys.argv.remove('--iocp')
        logging.info('using iocp')
        el = windows_events.ProactorEventLoop()
        events.set_event_loop(el)
 
    root_url = 'https://encompasshealth.com/concordrehab'
    crawler(root_url, out_file='sitemap.xml', client_config={'ssl': False})

5. 指定SSL协议版本

部分网站仅支持特定SSL/TLS版本,可手动指定协议版本,修改代码如下:

import sys
import logging
import ssl
from pysitemap import crawler

if __name__ == '__main__':
    if '--iocp' in sys.argv:
        from asyncio import events, windows_events
        sys.argv.remove('--iocp')
        logging.info('using iocp')
        el = windows_events.ProactorEventLoop()
        events.set_event_loop(el)
 
    root_url = 'https://encompasshealth.com/concordrehab'
    # 指定TLS 1.2协议
    ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    crawler(root_url, out_file='sitemap.xml', client_config={'ssl': ssl_context})

内容的提问来源于stack exchange,提问作者Muhammad Tayyab Shah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 02:36:18