我正在使用这个链接中的服务器和客户端程序:http://www.bogotobogo.com/python/python_network_programming_tcp_server_client_chat_server_chat_client_select.php
当我运行客户端时,我遇到以下错误:
Traceback (most recent call last):
File "client.py", line 26, in client
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
io.UnsupportedOperation: fileno我使用的是Python 3,但我在Python 2 to 3中使用print更改了所有行。
代码如下:
while 1:
socket_list = [sys.stdin, s]
# Get the list sockets which are readable
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])发布于 2015-06-27 04:51:41
虽然fileno()方法适用于普通的IO对象(sys.stdout、sys.stderr、sys.stdin和socket.socket),但空闲的Python IDE会更改IO对象,从而破坏了这一点。
所以..。如果遇到此错误,请直接从Python运行该命令。
发布于 2019-09-30 18:32:59
我最近在Travis CI上的测试用例中也得到了这个错误(Python2: AttributeError: StringIO实例没有' fileno‘属性;Python3: io.UnsupportedOperation: fileno),当Python代码执行命令并想要读取sys.stdout时
我猜在Travis CI包装命令输出并返回一个StringIO,而不是像往常一样返回一个文件对象。正如您在Travis CI的日志网页中看到的那样,包装的输出是白色,而不是通常的彩色。
所以我的方法不是执行一个命令,而是直接运行你自己的类的实例来测试。
我找遍了互联网,也没找到解决方案。我自己解决了这个问题,我想和其他人分享。
以防你还不明白我的意思。你可以看到这个提交:
https://github.com/martin68/apt-smart/commit/bb8fd766f7d96999a3a3fb79d089cde73c71ce83
https://stackoverflow.com/questions/31080829
复制相似问题