Skip to the content.

errno — POSIX error constants

import errno

Numeric constants for the errno values that OSError exceptions carry. Useful for distinguishing kinds of failures:

import errno
try:
    open('NOPE.TXT')
except OSError as e:
    if e.args[0] == errno.ENOENT:
        print('file not found')
    elif e.args[0] == errno.EACCES:
        print('permission denied')
    else:
        raise

Constants

The full list available in this port (matches the Linux subset uc386’s libc ships):

EPERM EACCES EAGAIN EBADF EBUSY ECHILD EDOM EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOMEM ENOSPC ENOSYS ENOTBLK ENOTDIR ENOTEMPTY ENOTTY ENXIO EOF EPIPE ERANGE EROFS ESPIPE ESRCH ETIMEDOUT ETXTBSY EXDEV

⚠️ The DOS errno set is smaller — most BSD/POSIX-flavoured errnos (EOPNOTSUPP, EADDRINUSE, etc.) aren’t present because the underlying DOS calls never produce them. The lwIP socket layer maps lwIP errors to POSIX errnos itself.

errno.errorcodedict[int, str]

Reverse lookup from errno number to name:

>>> errno.errorcode[2]
'ENOENT'
>>> errno.errorcode[errno.EACCES]
'EACCES'

Credit: MicroPython errno docs (MIT).