20
votes

I am using a server and the client programs from this link: http://www.bogotobogo.com/python/python_network_programming_tcp_server_client_chat_server_chat_client_select.php

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 1:
        socket_list = [sys.stdin, s]
        # Get the list sockets which are readable
        read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
2
What is s in your example? - Wolph
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - mee
I've just tried it locally and I had no issues. Which Python version are you running exactly? It appears to work with 3.4.3 - Wolph
it seems that the default version for the terminal is 2.7.6 but the idle i used to write this is 3.4.3. How can I change the default python used from terminal - mee
That depends on the operating system, but generally there are a few shortcuts. "python2" will give you the latest python 2 release and "python3" will give you the latest python 3 release. That's probably the easiest method to switch :) - Wolph

2 Answers

26
votes

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.

0
votes

I recently aiso 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