如何在 python 中获取 errno 值的错误消息?
我正在使用 ctypes 模块在 Linux 上执行一些 ptrace 系统调用,这实际上是有效的 很好。但如果我遇到错误,我想提供一些有用的信息。因此我 执行 get_errno() 函数调用,返回 errno 的值,但我没有找到 任何解释 errno 值并给我一个关联的函数或其他东西 错误信息。
我错过了什么吗? 有基于ctypes的解决方案吗?
这是我的设置:
import logging
from ctypes import get_errno, cdll
from ctypes.util import find_library, errno
# load the c lib
libc = cdll.LoadLibrary(find_library("c"), use_errno=True)
...
示例:
return_code = libc.ptrace(PTRACE_ATTACH, pid, None, None)
if return_code == -1:
errno = get_errno()
error_msg = # here i wanna provide some information about the error
logger.error(error_msg)
I am using the ctypes module to do some ptrace system calls on Linux, which actually works
pretty well. But if I get an error I wanna provide some useful information. Therefore I
do an get_errno() function call which returns the value of errno, but I didn't found
any function or something else which interprets the errno value and gives me an associated
error message.
Am I missing something?
Is there a ctypes based solution?
Here is my setup:
import logging
from ctypes import get_errno, cdll
from ctypes.util import find_library, errno
# load the c lib
libc = cdll.LoadLibrary(find_library("c"), use_errno=True)
...
Example:
return_code = libc.ptrace(PTRACE_ATTACH, pid, None, None)
if return_code == -1:
errno = get_errno()
error_msg = # here i wanna provide some information about the error
logger.error(error_msg)
这将打印
ENODEV: No such device
。This prints
ENODEV: No such device
.