aiosmtpd: RuntimeError after upgrading from 1.2.2

After upgrading from version 1.2.2 to 1.2.4 we receive the following error when trying to start the controller:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/aiosmtpd/", line 165, in start
    raise RuntimeError("Unknown Error, failed to init SMTP server")
RuntimeError: Unknown Error, failed to init SMTP server

This error can even be triggered by running the sample code from the documentation:

import asyncio
class ExampleHandler:
  async def handle_RCPT(self, server, session, envelope, address, rcpt_options):
    return '250 OK'

from aiosmtpd.controller import Controller
controller = Controller(ExampleHandler())

After executing “controller.start()” the RuntimeError from above appears.

Python version is 3.6.8 OS is Red Hat 7.9 aiosmtpd was installed with pip3. After downgrading via “sudo pip3 install aiosmtpd=1.2.2” everything works again and aiosmtpd receives and processes emails without problems.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 32

Commits related to this issue

Most upvoted comments

Hi, sure. I was thinking it can be similar one 😃 New one opened.

This has fixed the issue for me, thank you so much for the quick debugging and fix, @pepoluan!

Hello @pepoluan thank you very much! Looks very good, except that on my system the error 97 is thrown:

>>> from aiosmtpd.controller import Controller
>>> cont = Controller(ExampleHandler())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/aiosmtpd/", line 107, in __init__
    self.hostname = get_localhost() if hostname is None else hostname
  File "/usr/local/lib/python3.6/site-packages/aiosmtpd/", line 41, in get_localhost
    with makesock(AF_INET6, SOCK_STREAM) as sock:
  File "/usr/lib64/python3.6/", line 144, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
OSError: [Errno 97] Address family not supported by protocol

Errno 97 translates to errno.EAFNOSUPPORT, however get_localhost() is catching errno.EADDRNOTAVAIL. If I replace errno.EADDRNOTAVAIL with errno.EAFNOSUPPORT, version 1.3.1 works!

v1.3.1 is marinating, to be released tomorrow.

Definitely will fix @LeoVerto 's issue.

Not sure if it will fix @gnugnug 's issue, but at least 1.3.1 has more control points that can give more visibility into what’s going on.

Hey, someone else here!

I’ve been getting this issue with Python 3.9 in both alpine-based docker images and on my dev machine running Arch Linux, in both cases using a fresh virtualenv created by pipenv.

To reproduce this, clone my repository at this commit and replace line 90 in with config = {} to avoid having to set all the config environment variables. Next run pipenv install and finally pipenv run python to start the application.