Python Error: io.UnsupportedOperation: fileno
Asked Answered
K

2

29

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, [], [])
Kela answered 26/6, 2015 at 19:32 Comment(10)
What is s in your example?Benzedrine
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)Kela
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.3Benzedrine
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 terminalKela
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 :)Benzedrine
ok i tried running it with python3 but it still gives me the same errorKela
You probably have something strange in your environment, perhaps you're running python from an editor that changes your IO objects?Benzedrine
im running it from idle3.4Kela
There's your problem, try running it from straight up Python. IDLE messes with your IO :)Benzedrine
i did, and it works now, but it gives me another strange error. can you post a proper answer so that we dont hold a full conversation in the comments?Kela
B
31

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.

Benzedrine answered 26/6, 2015 at 20:51 Comment(0)
P
1

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

Paraffin answered 30/9, 2019 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.