Python Error: io.UnsupportedOperation: fileno

Question:

I am using a server and the client programs from here.

When I run the client I encounter the following error:

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

I am using Python 3, but I have changed all lines using print from Python 2 to 3.

Here is the code:

while True:
    socket_list = [sys.stdin, s]
    # Get the list sockets which are readable
    read_sockets, write_sockets, error_sockets = select.select(socket_list, [], [])
Asked By: mee

||

Answers:

While the fileno() method works on normal IO objects (sys.stdout, sys.stderr, sys.stdin and socket.socket), the IDLE Python IDE changes your IO objects which breaks this.

So… if you get this error, run the command from straight up Python instead.

Answered By: Wolph

I recently also got this error ( Python 2: AttributeError: StringIO instance has no attribute ‘fileno’ ; Python 3: io.UnsupportedOperation: fileno ) in test cases on Travis CI, when the python code excuted a command and wanted to read sys.stdout

I guess on Travis CI wraps command output and return a StringIO instead of a file object as usual. As you can see in the log webpage of Travis CI, the wrapped output is white color, instead of colorful as usual.

So my way is not to excuted a command, to run instance of your own class to be tested directly instead.

I searched all over the internet but failed to get a sulution. I solved this by myself and I want to share with others.

In case you still don’t understand what I meant. you can see this commit:

https://github.com/martin68/apt-smart/commit/bb8fd766f7d96999a3a3fb79d089cde73c71ce83

Answered By: Martin X
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.