Модуль errno
предоставляет символьное обозначение стандартных системных ошибок. Значение каждого символа - это соответствующее целочисленное значение. Имена и описания заимствованы из linux/include/errno.h
, что должно быть довольно всеобъемлющим.
errno.errorcode
:Словарь, обеспечивающий сопоставление значения errno
со строковым именем в базовой системе. Например, errno.errorcode[errno.EPERM]
выведет 'EPERM'
.
Чтобы преобразовать числовой код ошибки в сообщение об ошибке, используйте функцию os.strerror()
.
Смотрите примеры использования модуля errno
.
Из следующего списка символы, которые не используются на текущей платформе, не определены модулем. Конкретный список определенных символов доступен как errno.errorcode.keys()
.
errno.EPERM
: Operation not permittederrno.ENOENT
: No such file or directoryerrno.ESRCH
: No such processerrno.EINTR
: Interrupted system call.errno.EIO
: I/O errorerrno.ENXIO
: No such device or addresserrno.E2BIG
: Arg list too longerrno.ENOEXEC
: Exec format errorerrno.EBADF
: Bad file numbererrno.ECHILD
: No child processeserrno.EAGAIN
: Try againerrno.ENOMEM
: Out of memoryerrno.EACCES
: Permission deniederrno.EFAULT
: Bad addresserrno.ENOTBLK
: Block device requirederrno.EBUSY
: Device or resource busyerrno.EEXIST
: File existserrno.EXDEV
: Cross-device linkerrno.ENODEV
: No such deviceerrno.ENOTDIR
: Not a directoryerrno.EISDIR
: Is a directoryerrno.EINVAL
: Invalid argumenterrno.ENFILE
: File table overflowerrno.EMFILE
: Too many open fileserrno.ENOTTY
: Not a typewritererrno.ETXTBSY
: Text file busyerrno.EFBIG
: File too largeerrno.ENOSPC
: No space left on deviceerrno.ESPIPE
: Illegal seekerrno.EROFS
: Read-only file systemerrno.EMLINK
: Too many linkserrno.EPIPE
: Broken pipeerrno.EDOM
: Math argument out of domain of funcerrno.ERANGE
: Math result not representableerrno.EDEADLK
: Resource deadlock would occurerrno.ENAMETOOLONG
: File name too longerrno.ENOLCK
: No record locks availableerrno.ENOSYS
: Function not implementederrno.ENOTEMPTY
: Directory not emptyerrno.ELOOP
: Too many symbolic links encounterederrno.EWOULDBLOCK
: Operation would blockerrno.ENOMSG
: No message of desired typeerrno.EIDRM
: Identifier removederrno.ECHRNG
: Channel number out of rangeerrno.EL2NSYNC
: Level 2 not synchronizederrno.EL3HLT
: Level 3 haltederrno.EL3RST
: Level 3 reseterrno.ELNRNG
: Link number out of rangeerrno.EUNATCH
: Protocol driver not attachederrno.ENOCSI
: No CSI structure availableerrno.EL2HLT
: Level 2 haltederrno.EBADE
: Invalid exchangeerrno.EBADR
: Invalid request descriptorerrno.EXFULL
: Exchange fullerrno.ENOANO
: No anodeerrno.EBADRQC
: Invalid request codeerrno.EBADSLT
: Invalid sloterrno.EDEADLOCK
: File locking deadlock errorerrno.EBFONT
: Bad font file formaterrno.ENOSTR
: Device not a streamerrno.ENODATA
: No data availableerrno.ETIME
: Timer expirederrno.ENOSR
: Out of streams resourceserrno.ENONET
: Machine is not on the networkerrno.ENOPKG
: Package not installederrno.EREMOTE
: Object is remoteerrno.ENOLINK
: Link has been severederrno.EADV
: Advertise errorerrno.ESRMNT
: Srmount errorerrno.ECOMM
: Communication error on senderrno.EPROTO
: Protocol errorerrno.EMULTIHOP
: Multihop attemptederrno.EDOTDOT
: RFS specific errorerrno.EBADMSG
: Not a data messageerrno.EOVERFLOW
: Value too large for defined data typeerrno.ENOTUNIQ
: Name not unique on networkerrno.EBADFD
: File descriptor in bad stateerrno.EREMCHG
: Remote address changederrno.ELIBACC
: Can not access a needed shared libraryerrno.ELIBBAD
: Accessing a corrupted shared libraryerrno.ELIBSCN
: .lib
section in a.out
corruptederrno.ELIBMAX
: Attempting to link in too many shared librarieserrno.ELIBEXEC
: Cannot exec a shared library directlyerrno.EILSEQ
: Illegal byte sequenceerrno.ERESTART
: Interrupted system call should be restartederrno.ESTRPIPE
: Streams pipe errorerrno.EUSERS
: Too many userserrno.ENOTSOCK
: Socket operation on non-socketerrno.EDESTADDRREQ
: Destination address requirederrno.EMSGSIZE
: Message too longerrno.EPROTOTYPE
: Protocol wrong type for socketerrno.ENOPROTOOPT
: Protocol not availableerrno.EPROTONOSUPPORT
: Protocol not supportederrno.ESOCKTNOSUPPORT
: Socket type not supportederrno.EOPNOTSUPP
: Operation not supported on transport endpointerrno.EPFNOSUPPORT
: Protocol family not supportederrno.EAFNOSUPPORT
: Address family not supported by protocolerrno.EADDRINUSE
: Address already in useerrno.EADDRNOTAVAIL
: Cannot assign requested addresserrno.ENETDOWN
: Network is downerrno.ENETUNREACH
: Network is unreachableerrno.ENETRESET
: Network dropped connection because of reseterrno.ECONNABORTED
: Software caused connection aborterrno.ECONNRESET
: Connection reset by peererrno.ENOBUFS
: No buffer space availableerrno.EISCONN
: Transport endpoint is already connectederrno.ENOTCONN
: Transport endpoint is not connectederrno.ESHUTDOWN
: Cannot send after transport endpoint shutdownerrno.ETOOMANYREFS
: Too many references: cannot spliceerrno.ETIMEDOUT
: Connection timed outerrno.ECONNREFUSED
: Connection refusederrno.EHOSTDOWN
: Host is downerrno.EHOSTUNREACH
: No route to hosterrno.EALREADY
: Operation already in progresserrno.EINPROGRESS
: Operation now in progresserrno.ESTALE
: Stale NFS file handleerrno.EUCLEAN
: Structure needs cleaningerrno.ENOTNAM
: Not a XENIX named type fileerrno.ENAVAIL
: No XENIX semaphores availableerrno.EISNAM
: Is a named type fileerrno.EREMOTEIO
: Remote I/O errorerrno.EDQUOT
: Quota exceedederrno
:>>> import errno >>> errno.errorcode.keys() dict_keys( [19, 50, 113, 42, 117, 45, 51, 61, 15, 38, 32, 22, 75, 68, 4, 87, 39, 105, 71, 66, 119, 10, 40, 18, 7, 3, 90, 97, 53, 112, 96, 92, 16, 11, 77, 73, 106, 55, 108, 44, 80, 64, 52, 9, 72, 5, 49, 91, 28, 8, 114, 100, 118, 13, 48, 84, 20, 76, 1, 33, 54, 111, 21, 93, 30, 99, 43, 70, 69, 121, 47, 74, 23, 82, 29, 67, 102, 110, 2, 17, 122, 60, 57, 56, 79, 14, 27, 35, 107, 89, 81, 37, 120, 103, 101, 116, 63, 12, 88, 86, 31, 34, 83, 46, 104, 98, 95, 78, 36, 25, 85, 94, 62, 59, 109, 24, 26, 115, 6, 65, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132 ]) >>> errno.errorcode[errno.EPERM] 'EPERM' >>> import os # получение сообщения об ошибке из кода ошибки >>> os.strerror(19) # 'No such process' >>> os.strerror(50) # 'No CSI structure available' >>> os.strerror(19) # 'No such device' >>> os.strerror(113) # 'No route to host'