classification
Title: AttributeError: addinfourl instance has no attribute 'tell'
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: ProgVal, Valentin.Lorentz, amaury.forgeotdarc, ctheune, eric.araujo, orsenthil, r.david.murray
Priority: normal Keywords:

Created on 2010-11-08 17:38 by Valentin.Lorentz, last changed 2014-04-19 08:30 by orsenthil. This issue is now closed.

Messages (15)
msg120781 - (view) Author: ProgVal (Valentin.Lorentz) Date: 2010-11-08 17:38
Hello,

I had this traceback:

Traceback (most recent call last):
...
  File "/home/progval/workspace/Supybot/Supybot-plugins/Packages/plugin.py", line 123, in extractData
    file = tarfile.open(fileobj=file_)
  File "/usr/lib/python2.6/tarfile.py", line 1651, in open
    saved_pos = fileobj.tell()
AttributeError: addinfourl instance has no attribute 'tell'

The repr(file_) is : <addinfourl at 47496224 whose fp = <socket._fileobject object at 0x2c933d0>> (the file has been downloaded with urllib).

I use Python 2.6.6 (from Debian Sid repo)

Best regards,
ProgVal
msg120783 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-11-08 17:47
With a socket file you cannot rely on autodetection of the format. I suggest to try
   tarfile.open(fileobj=file_, mode='r:')
or 
   tarfile.open(fileobj=file_, mode='r:gz')
msg120784 - (view) Author: ProgVal (Valentin.Lorentz) Date: 2010-11-08 17:57
Thanks for your answer.

Sorry, no change...
msg120786 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-11-08 18:04
I'm sure the traceback changed then?
mode='r:' uses a different code path.
msg120787 - (view) Author: ProgVal (Valentin.Lorentz) Date: 2010-11-08 18:16
Here is the new traceback:
Traceback (most recent call last):
...
  File "/home/progval/workspace/Supybot/Supybot-plugins/Packages/plugin.py", line 123, in extractData
    file = tarfile.open(fileobj=file_, mode='r:')
  File "/usr/lib/python2.6/tarfile.py", line 1671, in open
    return func(name, filemode, fileobj, **kwargs)
  File "/usr/lib/python2.6/tarfile.py", line 1698, in taropen
    return cls(name, mode, fileobj, **kwargs)
  File "/usr/lib/python2.6/tarfile.py", line 1563, in __init__
    self.offset = self.fileobj.tell()
AttributeError: addinfourl instance has no attribute 'tell'
msg121855 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-21 03:34
2.6 only gets security fixes.  Can you reproduce the bug with current versions?
msg121872 - (view) Author: ProgVal (ProgVal) Date: 2010-11-21 07:04
I also have the bug with Python 2.7.1rc1 (from Debian 'Experimental' repo)
msg121939 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-21 15:18
Thanks.  Do you want to work on a patch?  We need to had a test to reproduce the error and then fix the code.
msg121942 - (view) Author: ProgVal (ProgVal) Date: 2010-11-21 15:49
Same result on all tested versions (2.5 -> 2.7) :

------------------------------------------
import urllib2
import tarfile

tarfile.open(fileobj=open('/home/progval/Downloads/GoodFrench.tar'), mode='r:') # Works
tarfile.open(fileobj=urllib2.urlopen(urllib2.Request('http://plugins.supybot-fr.tk/GoodFrench.tar')), mode='r:') # Fails
------------------------------------------

I don't understand, because /home/progval/Downloads/GoodFrench.tar is the same file...


I don't know if I have the skills to do the patch, I use Python for less than 9 months...
msg121945 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-21 15:53
2.5 and 2.6 don’t get bug fixes anymore, only security fixes.  If you want to try to fix the code, there are some guidelines at http://www.python.org/dev/patches/
msg121949 - (view) Author: ProgVal (ProgVal) Date: 2010-11-21 16:05
This code :
import urllib2
print urllib2.urlopen('http://plugins.supybot-fr.tk/GoodFrench.tar').read(500)

Prints :
data/0000755000175000017500000000000011466030066011677 5ustar  progvalprogval



If the problem comes from networking libraries, I really don't have the skills :s
msg122353 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-25 11:38
If you want to quickly solve this, do like this:

import urllib
import tarfile

tarfile.open(urllib.urlretrieve('http://plugins.supybot-fr.tk/GoodFrench.tar')[0], mode='r:') # Works

The problem is tarfile is expecting a "file-object" with a tell method for seeking, whereas urllib2 returns a file-like object, which does have a tell method. It seems to not have because, the underlying socket._fileobject is not exposing one (for whatever reason). Let me try to figure out reason for fixing/closing this bug.
(BTW, http module is relying on .tell() of the socket._fileobject too and I wonder it did not get noticed earlier because the has not taken that path yet? Strange!)
msg216726 - (view) Author: Christian Theune (ctheune) * Date: 2014-04-17 18:34
I don't think this will be solved. File-like objects (in this case IO wrappers for the socket) may have different capabilities and tarfile is just expecting too much.

My patch for #15002 relieved the situation somewhat by providing tell() but the IO stream just isn't seekable. I think you'll have to download to a temporary file first to give tarfile all the capabilities it needs.

I guess this should be rejected.
msg216729 - (view) Author: Christian Theune (ctheune) * Date: 2014-04-17 18:45
Not being an export on tar at all, but I tried getting anything working without tell() and seek() but couldn't.

The code reads as if its supposed to support some tar formats that do not require seeking, but that would be rather hard to predict on a file-by-file basis, I guess.
msg216851 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2014-04-19 08:30
I agree. Having tell on a file descriptor of a URL request is not going to be of help. You can easily write to a local file and use all the local file features, if it is things like .tell is desired.
History
Date User Action Args
2014-04-19 08:30:42orsenthilsetstatus: open -> closed
resolution: not a bug
messages: + msg216851

stage: needs patch -> resolved
2014-04-17 18:45:33ctheunesetmessages: + msg216729
2014-04-17 18:34:25ctheunesetnosy: + r.david.murray, ctheune
messages: + msg216726
2010-11-25 11:38:59orsenthilsetassignee: orsenthil
messages: + msg122353
2010-11-21 16:05:02ProgValsetmessages: + msg121949
2010-11-21 15:53:01eric.araujosetmessages: + msg121945
2010-11-21 15:50:00ProgValsetmessages: + msg121942
2010-11-21 15:18:33eric.araujosetversions: + Python 3.1, Python 3.2, - Python 2.6
nosy: + orsenthil

messages: + msg121939

type: behavior
stage: needs patch
2010-11-21 07:04:19ProgValsetnosy: + ProgVal

messages: + msg121872
versions: + Python 2.6, - Python 3.1, Python 3.2
2010-11-21 03:34:51eric.araujosetnosy: + eric.araujo

messages: + msg121855
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2010-11-08 18:16:33Valentin.Lorentzsetmessages: + msg120787
2010-11-08 18:04:03amaury.forgeotdarcsetmessages: + msg120786
2010-11-08 17:57:30Valentin.Lorentzsetmessages: + msg120784
components: + Library (Lib)
versions: + Python 2.6
2010-11-08 17:47:19amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg120783
2010-11-08 17:38:06Valentin.Lorentzcreate