tarfile : read from a socket?
Ulli Horlacher
framstag at rus.uni-stuttgart.de
Thu Feb 11 08:25:26 EST 2016
Ulli Horlacher <framstag at rus.uni-stuttgart.de> wrote:
> I have:
>
> sock = socket.create_connection((server,port))
> bs = kB64
> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
>
>
>
> Traceback (most recent call last):
> (...)
> File "./fexit.py", line 1838, in sex_send
> taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w')
> File "/usr/lib/python2.7/tarfile.py", line 1695, in open
> return cls.taropen(name, mode, fileobj, **kwargs)
> File "/usr/lib/python2.7/tarfile.py", line 1705, in taropen
> return cls(name, mode, fileobj, **kwargs)
> File "/usr/lib/python2.7/tarfile.py", line 1566, in __init__
> self.offset = self.fileobj.tell()
> AttributeError: '_fileobject' object has no attribute 'tell'
Reading the doc helps :-)
https://docs.python.org/2/library/tarfile.html
For special purposes, there is a second format for mode:
'filemode|[compression]'. tarfile.open() will return a TarFile object
that processes its data as a stream of blocks.
With
taro = tarfile.open(fileobj=sock.makefile('w',kB64),mode='w|')
I get no more error.
--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-68565868
Allmandring 30a Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/
More information about the Python-list
mailing list