Issue 36047: socket file handle does not support stream write (original) (raw)

Python3 programmers have forgotten to convert/implement the socket file descriptor for IO stream operation. Would you please add it? Thanks!

import socket s = socket.socket() s.connect('localhost', 5432) S = s.makefile()

on Python2, the following works

print >>S, 'hello world' S.flush()

on Python3, the same thing does not work

print('hello world', file=S, flush=True)

It gives the following error: Traceback (most recent call last): File "", line 1, in io.UnsupportedOperation: not writable

Luckily, the stream read operation works, S.readline()

I confirm that you don't use socket.makefile in write mode.

Python 3.7.2 (default, Jan 16 2019, 19:49:22) [GCC 8.2.1 20181215 (Red Hat 8.2.1-6)] on linux Type "help", "copyright", "credits" or "license" for more information.

import socket s = socket.socket() s.connect('localhost', 5432) Traceback (most recent call last): File "", line 1, in TypeError: connect() takes exactly one argument (2 given) s.connect(('localhost', 5432)) S = s.makefile() print('hello world', file=S, flush=True) Traceback (most recent call last): File "", line 1, in io.UnsupportedOperation: not writable S = s.makefile(mode='w') print('hello world', file=S, flush=True)

I close the issue.