Python's Sendmail fails due to access permissions

A script that ran happily for about a year suddenly stopped working last week. From the stack trace, it was apparent that the script was stumbling on Python's smtplib>sendmail command. Here's the error:

OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

The offending code:

s = smtplib.SMTP(config['smtpserver']['server'])
s.sendmail(fromAddress, toAddress, msg.as_string())

The best suggestion I found is that Windows UAC is likely preventing the successful sendmail1. Since I've already worked through a way to elevate a script's privilege, the same solution can be applied here.

Doing an import admin and then, early in the script, checking for admin privilege, does the trick:

if not admin.isUserAdmin():

  1. I have no idea what changed recently in security settings to cause this error to suddenly crop up. ¯_(ツ)_/¯ ↩︎

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.