remram44 / yoppi

An automatic FTP indexer written in Python. Inspired by Yoshi Indexer (written in PHP).
GNU General Public License v3.0
6 stars 2 forks source link

Exception EOFError while indexing #25

Closed remram44 closed 12 years ago

remram44 commented 12 years ago
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/var/www/yoppi/env/lib/python2.7/site-packages/django/core/management/__
init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/var/www/yoppi/env/lib/python2.7/site-packages/django/core/management/__
init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/www/yoppi/env/lib/python2.7/site-packages/django/core/management/ba
se.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/var/www/yoppi/env/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/var/www/yoppi/yoppi/yoppi/indexer/management/commands/scan.py", line 21, in handle
    indexer.scan(args[0], args[1])
  File "/var/www/yoppi/yoppi/yoppi/indexer/app.py", line 142, in scan
    for ip in IPRange(min_ip, max_ip))
  File "/var/www/yoppi/yoppi/yoppi/indexer/app.py", line 142, in <genexpr>
    for ip in IPRange(min_ip, max_ip))
  File "/var/www/yoppi/yoppi/yoppi/indexer/app.py", line 102, in _scan_address
    if ftp_online(address, self.timeout):
  File "/var/www/yoppi/yoppi/yoppi/indexer/app.py", line 57, in ftp_online
    ftp.connect(address)
  File "/usr/local/lib/python2.7/ftplib.py", line 135, in connect
    self.welcome = self.getresp()
  File "/usr/local/lib/python2.7/ftplib.py", line 210, in getresp
    resp = self.getmultiline()
  File "/usr/local/lib/python2.7/ftplib.py", line 196, in getmultiline
    line = self.getline()
  File "/usr/local/lib/python2.7/ftplib.py", line 186, in getline
    if not line: raise EOFError
EOFError
remram44 commented 12 years ago

It seems that this happens on a server that immediately closes the TCP connection when it is established.

I am not sure what kind of exceptions ftplib can throw, there might be more that we don't currently catch.

remram44 commented 12 years ago

This is "kind of fixed" by ab945e3dfa. It appears there is no clear hierarchy for these exceptions so catching them all would be a bother. I catch Exception instead.

madjar commented 12 years ago

The ftplib source code contains this interesting couple of lines (couple of lines):

# All exceptions (hopefully) that may be raised here and that aren't
# (always) programming errors on our side
all_errors = (Error, IOError, EOFError)

So I guess this should do the trick : except ftplib.all_errors.

Because there is a special place in hell for people who write except Exception.

remram44 commented 12 years ago

I find except to be dangerous, but except Exception is useful. This might do the trick, here it is set to: (ftplib.Error, IOError, EOFError, ssl.SSLError)

madjar commented 12 years ago

except Exception will catch any typo you do in the try block and might make debugging a living hell.

remram44 commented 12 years ago

Pushed as c94ceedff2.