ftplib throws: IndexError: tuple index out of range

Peter Otten __peter__ at web.de
Sun Feb 14 08:40:35 EST 2016


Antoon Pardon wrote:

> I have written a small backup program, that uses ftplib to make
> remote backups. However recentely the program starts to regularly
> raise IndexErrors, as far as I can see the problem is in socket.py
> Can anyone shed some light?
> 
> This is the traceback:

[...]

>   File "/usr/lib/python2.7/socket.py", line 478, in readline
>     if e.args[0] == EINTR:
> IndexError: tuple index out of range

The offending line seems to be part of

                try:
                    data = self._sock.recv(self._rbufsize)
                except error, e:
                    if e.args[0] == EINTR:
                        continue
                    raise


> Locals by frame, innermost last

[...]

> Frame readline in /usr/lib/python2.7/socket.py at line 478
>                  buf = <cStringIO.StringO object at 0x7ff8c5d40298>
>              buf_len = 0
>                    e = timeout()
>                 self = <socket._fileobject object at 0x7ff8c7b75b50>
>                 size = 8193

It looks like the actual error is socket.timeout which is probably raised 
from somewhere inside the stdlib without args. 

I think this is a bug in socket.py; the error handler should special-case 
with either

try:
     ...
except timeout, e:
    raise
except error, e:
    ...


or

try:
    ...
except error, e:
    if e.args and e.args[0] == EINTR:
        continue
    raise

You will still have to find the cause and handle the effects of the timeout.

PS: How did you produce the overview over the local variables? That looks 
nice.




More information about the Python-list mailing list