相同的错误代码 [英] Identical Error Codes

查看:90
本文介绍了相同的错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上使用python 2.4.1,并在我所在公司内部编写了一个python包,用于在两个主机之间建立连接以进行测试。



在建立连接时,通过使用错误代码111调用 socket.connect 与正确的参数(我检查),定义为客户端的一方失败。在搜索Web后,错误意味着,我知道这意味着连接被积极拒绝。



但是,用于建立连接的包中的代码应该处理它,只有它知道10061作为同一错误的错误代码:连接被拒绝。



可能是相同的逻辑错误有相同的错误代码?可能是111是Linux操作系统的系统错误,因为10061是python的甚至是另一个操作系统?即使如此,错误代码的整体概念不是统一逻辑错误与相同的代码?



我应该将111错误代码添加到处理条件?

解决方案

似乎Python正在暴露出来自操作系统的错误代码 - 代码的解释与操作系统相关。许多Linux系统和Cygwin上的

111是 ECONNREFUSED



<

10061 WSAECONNREFUSED in winerror.h - 它是Windows Socket API的版本 ECONNREFUSED



毫无疑问,在其他系统上,它是不同的。



正确的处理方式是根据操作系统的定义 ECONNREFUSED 使用符号比较;这就是你在C中的做法,例如。换句话说,有一个叫做ECONNREFUSED的常量,在平台特定的库(在任何情况下链接到操作系统的套接字基元都是必要的),该平台具有ECONNREFUSED的值,并将错误代码与ECONNREFUSED常量进行比较而不是魔术数字。



我不知道Python的标准操作系统错误代码是什么。我怀疑这不是很好的想法。


I use python 2.4.1 on Linux, and a python package written inside the company I work in, for establishing a connection between 2 hosts for test purposes.

Upon establishing the connection the side defined as the client side failed when calling socket.connect with the correct parameters (I checked) with the error code 111. After searching the web for this error means, I learned that it means that the connection was actively refused.

But the code in the package for establishing the connection is supposed to deal with it, only it knows 10061 as the error code for this same error: The connection is refused.

Could it be that there are identical error codes for the same logical errors? Could it be that 111 is a system error of the Linux OS, as 10061 is python's or even another OS? Even so, isn't the entire concept of error codes to unify the logical errors with the same codes?

Should I simply add the 111 error code to the handling condition?

解决方案

It appears Python is exposing the error code from the OS - the interpretation of the code is OS-dependent.

111 is ECONNREFUSED on many Linux systems, and on Cygwin.

146 is ECONNREFUSED on Solaris.

10061 is WSAECONNREFUSED in winerror.h - it's the Windows Socket API's version of ECONNREFUSED.

No doubt on other systems, it's different again.

The correct way to handle this is use symbolic comparisons based on the OS's definition of ECONNREFUSED; that's the way you do it in C, for example. In other words, have a constant called ECONNREFUSED that has the value of ECONNREFUSED for that platform, in a platform-specific library (which will be necessary to link to the OS's socket primitives in any case), and compare error codes with the ECONNREFUSED constant, rather than magic numbers.

I don't know what Python's standard approach to OS error codes is. I suspect it's not terribly well thought out.

这篇关于相同的错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆