Automatically renewing Let’s Encrypt SSL Certificates on PythonAnywhere

Several months ago, I set up a small webapp using PythonAnywhere. It’s a really easy to use service and for small projects is hard to beat since there is so little setup. They even let you use Let’s Encrypt (albeit in a hackish way) for free SSL certificates!

The problem that I’ve run into is that due to the way Let’s Encrypt is set up on PythonAnywhere, there’s no easy way to configure an auto renewal. Usually, one would just set up a cronjob set to run every 3 months. This doesn’t work for two reasons: the first is that there _is no cron_ on PythonAnywhere, and the other is that you must manually email the PythonAnywhere staff when your certificate is actually updated and they do the “installation”. Multiple times now, I’ve forgotten to renew until someone came to me telling me that the site wouldn’t let them do anything because of an expired certificate.

I got sick of feeling dumb and wrote a simple Python script that automatically renews the certificate and sends an email to the PythonAnywhere staff letting them know that it’s ready to be installed.
It’s scheduled using the PythonAnywhere scheduled tasks, and even though it runs every day, the renewal itself only takes place when the certificate is set to expire within 29 days or less.

If this sounds like something that would be helpful, its on my GitHub page.

Leave a Reply

Your email address will not be published. Required fields are marked *