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():
admin.runAsAdmin()
-
I have no idea what changed recently in security settings to cause this error to suddenly crop up. ¯_(ツ)_/¯ ↩︎