gpt4 book ai didi

python-3.x - 调试由服务器重新启动修复的 Twilio SSL 错误(错误 11220)

转载 作者:行者123 更新时间:2023-12-04 22:39:09 24 4
gpt4 key购买 nike

我有一个基本的 rest api 服务器,它使用 Twilio api 接受传入的短信和回复。
每两个月左右我就会注意到我需要重新启动服务器,因为 Twilio 开始给我 SSL 握手错误。这与 https 证书没有任何关系,因为正如我所提到的,它是通过简单的重新启动来修复的。我正在寻求帮助调试这个。
工具的结构
app.py - FastApi 休息服务器。有一个/webhook 端点来接受 Twilio 传入消息请求。
utils.py - 具有用于通过 Twilio api 发送短信的方法的 Utils 文件。

TWILIO_CLIENT = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)

async def send_twilio_sms(twilio_message: TwilioMessage):
"""
Send the message via twilio
"""
try:
ph_number = twilio_message.phone_number
message = twilio_message.message
msg = TWILIO_CLIENT.messages.create(to=ph_number,
messaging_service_sid=TWILIO_MESSAGING_SERVICE_SID,
body=message)
except TwilioRestException as e:
raise
return msg, msg.sid

uvicorn 的实际服务器也非常基础 sudo ~/.pyenv/versions/myproject/bin/uvicorn app:app --port xxxx --host 0.0.0.0 --ssl-keyfile=/etc/letsencrypt/live/myprojectdomain/privkey.pem --ssl-certfile=/etc/letsencrypt/live/myprojectdomain/fullchain.pem

最佳答案

您没有在问题中包含最重要的信息,即带有 SSL 错误的实际日志。所以我要做一个最好的猜测。
Let's Encrypt 证书需要每三个月更新一次。我的假设是你有一个运行 certbot 的 cron 作业、计时器或类似的作业。定期更新任何接近其到期日期的证书。更新非常透明,fullchain.pem文件刚刚更新到位。
因此,在最好的情况下,您需要重新启动 uvicorn每三个月一次,只是为了重新加载证书。看看--post-hook certbot renew 的选项命令:https://certbot.eff.org/docs/using.html?highlight=hook#renewing-certificates .这允许您在更新证书后添加自定义命令。您将使用它向您的 uvicorn 进程发送信号以重新加载或重新启动。
此外,这与您的问题无关,但您应该知道 Twilio 库在 asyncio 下阻塞,因此您应该在执行程序或其他防止异步循环阻塞的方法中运行任何调用 Twilio API 的函数。我的 Using the Twilio Python Helper Library in your Async Applications Twilio 博客上的文章将为您提供您拥有的选项列表。

关于python-3.x - 调试由服务器重新启动修复的 Twilio SSL 错误(错误 11220),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66533186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com