Python Error: io.UnsupportedOperation: fileno

前端 未结 2 1228
耶瑟儿~
耶瑟儿~ 2020-11-29 10:02

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<

相关标签:
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

    0 讨论(0)
  • 2020-11-29 10:35

    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 讨论(0)
提交回复
热议问题