Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Linux 下 multimedia.nt.qq.com.cn SSLV3错误 #681

Open
1 of 2 tasks
NepPure opened this issue Mar 3, 2025 · 2 comments
Open
1 of 2 tasks

[Bug] Linux 下 multimedia.nt.qq.com.cn SSLV3错误 #681

NepPure opened this issue Mar 3, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@NepPure
Copy link

NepPure commented Mar 3, 2025

发生了什么

错误信息和 #196 一致

如何复现?

问题来自高版本request库修复默认值带来的安全问题引发的连锁反应,详情见 psf/requests#6616

AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

修复方案可参考 SengokuCola/MaiMBot#13

操作系统

Linux

报错日志

#196

你愿意提交 PR 吗?

  • 是的,我愿意提交 PR!

Code of Conduct

@NepPure NepPure added the bug Something isn't working label Mar 3, 2025
@NepPure
Copy link
Author

NepPure commented Mar 3, 2025

实测降级库版本也能修复,暴力替换指定域名用http也行

@Soulter
Copy link
Owner

Soulter commented Mar 3, 2025

Hi, 参考了提到的方法,https://vscode.dev/github/Soulter/AstrBot/blob/master/astrbot/core/utils/io.py#L103 给这里加如下代码试试能不能正常工作:

async def download_image_by_url(
    url: str, post: bool = False, post_data: dict = None, path=None
) -> str:
    """
    下载图片, 返回 path
    """
    try:
        async with aiohttp.ClientSession(trust_env=True) as session:
            if post:
                async with session.post(url, json=post_data) as resp:
                    if not path:
                        return save_temp_img(await resp.read())
                    else:
                        with open(path, "wb") as f:
                            f.write(await resp.read())
                        return path
            else:
                async with session.get(url) as resp:
                    if not path:
                        return save_temp_img(await resp.read())
                    else:
                        with open(path, "wb") as f:
                            f.write(await resp.read())
                        return path
    except aiohttp.client.ClientConnectorSSLError:
        # 关闭SSL验证
        ssl_context = ssl.create_default_context()
        ssl_context.check_hostname = False
        ssl_context.verify_mode = ssl.CERT_NONE
        ssl_context.set_ciphers("AES")
        async with aiohttp.ClientSession() as session:
            if post:
                async with session.get(url, ssl=ssl_context) as resp:
                    return save_temp_img(await resp.read())
            else:
                async with session.get(url, ssl=ssl_context) as resp:
                    return save_temp_img(await resp.read())
    except Exception as e:
        raise e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants