gpt4 book ai didi

python - 当发生套接字错误时,如何从异常中获取其错误代码?

转载 作者:行者123 更新时间:2023-12-03 08:15:15 27 4
gpt4 key购买 nike

像这样的代码:

import socket, sys

try:
address = ('127.0.0.1', 31500)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(address)
except Exception:
errType, errValue, errTraceback = sys.exc_info()
# or
# handle the Exception it throw out ?

我想要得到的是类似 10060的错误代码,这意味着 connection time out,感谢您的帮助:)

最佳答案

采用

except EnvironmentError as e:
print e.errno

关于python - 当发生套接字错误时,如何从异常中获取其错误代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488822/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com