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 , [], [])
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0