1. Dane Springmeyer
  2. django-shapes
  3. Issues
Issue #5 open

Sporadic Error in ShapeResponder

created an issue

This error doesn't happen all the time.

To get it I entered a URL that will return a zipped up shapefile.

It worked

Then clicking on another URl that also returns a shapfile failed.

Finally, clicking on the original shapefile failed as well.

Here is the error:

Here is the error message I received. Looks like an issue with a tmp directory...


Request Method: GET Request URL: http://optiplexe:8000/burnedarea/53.shp Django Version: 1.0-final-SVN-9084 Python Version: 2.5.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.gis', 'django_nasa_fire_dss.fire', 'django_nasa_fire_dss.shapes'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware')

Traceback: File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, callback_args, *callback_kwargs) File "/home/chatt/svn/nasa_fire_dss/trunk/src/django_nasa_fire_dss/fire/views.py" in single_burnedarea_shp 34. return shp_response() File "/home/chatt/svn/nasa_fire_dss/trunk/src/django_nasa_fire_dss/shapes/views/export.py" in call 127. zip.write(filename, '%s.%s' % (self.file_name, item)) File "/usr/lib/python2.5/zipfile.py" in write 541. st = os.stat(filename)

Exception Type: OSError at /burnedarea/53.shp Exception Value: [Errno 2] No such file or directory: '/tmp/tmpsOrzg.shp'

Comments (6)

  1. Dane Springmeyer repo owner

    Yup, I've seen that too. Usually attempting to refresh the page will kick off the download again successfully.

    Thanks for noting it. It may require some attention to better use of the tempfile module, which I'm no pro at yet.

  2. crhatt reporter

    Is it related to this, from the python documentation on tempfile:

    tempfile.mktemp([suffix=''[, prefix='tmp'[, dir=None]]])

    Deprecated since version 2.3: Use mkstemp() instead.

    Return an absolute pathname of a file that did not exist at the time the call is made. The prefix, suffix, and dir arguments are the same as for mkstemp().


    Use of t his function may introduce a security hole in your program. By the time you get around to doing anything with the file name it returns, someone else may have beaten you to the punch. mktemp() usage can be replaced easily with NamedTemporaryFile(), passing it the delete=False parameter:

    >>> f = NamedTemporaryFile(delete=False) >>> f <open file '<fdopen>', mode 'w+b' at 0x384698> >>> f.name '/var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/tmpG7V1Y0' >>> f.write("Hello World!\n") >>> f.close() >>> os.unlink(f.name) >>> os.path.exists(f.name) False

  3. crhatt reporter


    Now, I'm not sure what the solution is, but if it is to add something like:

    tmp = tempfile.NamedTemporaryFile(suffix='.shp', mode = 'w', delete = False)

    How will we make sure it is eventually deleted?

  4. Dane Springmeyer repo owner

    I think unlinking the file if delete=False won't be a big issue, but I just read that the 'delete' kwargs is only available in python 2.6, so that's a no go for now.

    It's funny that tmp.close() seems to work in most cases. The python docs for NamedTemporaryFile seem to indicate that the tmp file should be deleted once closed.

    If we don't close the tmp file thought, then gdal can't read from it and gives 'OGRException: Invalid handle.'

    Crhatt, have you been able to replicate this consistently in any way?

  5. Log in to comment