Check your email addresses in Python, as a whole
May 22, 2020
0 comments Python, MDN
So recently, in MDN, we changed the setting WELCOME_EMAIL_FROM
. Seems harmless right? Wrong, it failed horribly in runtime and we didn't notice until it was in production. Here's the traceback:
SMTPSenderRefused: (552, b"5.1.7 The sender's address was syntactically invalid.\n5.1.7 see : http://support.socketlabs.com/kb/84 for more information.", '=?utf-8?q?Janet?=') (8 additional frame(s) were not displayed) ... File "newrelic/api/function_trace.py", line 151, in literal_wrapper return wrapped(*args, **kwargs) File "django/core/mail/message.py", line 291, in send return self.get_connection(fail_silently).send_messages([self]) File "django/core/mail/backends/smtp.py", line 110, in send_messages sent = self._send(message) File "django/core/mail/backends/smtp.py", line 126, in _send self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n')) File "python3.8/smtplib.py", line 871, in sendmail raise SMTPSenderRefused(code, resp, from_addr) SMTPSenderRefused: (552, b"5.1.7 The sender's address was syntactically invalid.\n5.1.7 see : http://support.socketlabs.com/kb/84 for more information.", '=?utf-8?q?Janet?=')
Yikes!
So, to prevent this from happening every again we're putting this check in:
from email.utils import parseaddr
WELCOME_EMAIL_FROM = config("WELCOME_EMAIL_FROM", ...)
# If this fails, SMTP will probably also fail.
assert parseaddr(WELCOME_EMAIL_FROM)[1].count('@') == 1, parseaddr(WELCOME_EMAIL_FROM)
You could go to town even more on this. Perhaps use the email validator within django
but for now I'd call that overkill. This is just a decent check before anything gets a chance to go wrong.
MDN Documents Size Tree Map
November 14, 2019
0 comments MDN, Web development
Recently I've been playing with the content of MDN as a whole. MDN has ~140k documents in its Wiki. About ~70k of them are redirects which is the result of many years of switching tech and switching information architecture and at the same time being good Internet citizens and avoiding 404s. So, out of the ~70k documents, how do they spread? To answer that I wrote a Python script that evaluates size as a matter of the sum of all the files in sub-trees including pictures.
Here are the screenshots:
All locales
Specifically en-US
The code that puts this together uses Toast UI which seems cool but I didn't spend much time worrying about how to use it.
Be warned! Opening this link will make your browser sweat: https://8mw9v.csb.app/
You can fork it here: https://codesandbox.io/s/zen-swirles-8mw9v