geodesign / django-raster

Django-raster allows you to create tiled map services (TMS) and raster map algebra end points for web maps. It is Python-based, and requires GeoDjango with a PostGIS backend.
BSD 3-Clause "New" or "Revised" License
96 stars 39 forks source link

PermissionError at /admin/raster/rasterlayer/add/ #45

Open maulanarachmat opened 4 years ago

maulanarachmat commented 4 years ago

I'm trying to add raster into Raster layers using admin page, but everytime i tried it always give [WinError 32], I already tried to change permission on admin page and remove the file on temp data but still got the error.

I'm using Windows 10, PostgreSQL 11.4, PostGIS 2.5.3 and Python 3 using virtual env from conda. My data only have 1 band (grayscale)

Here's the traceback error:

Environment:

Request Method: POST Request URL: http://127.0.0.1:8000/admin/raster/rasterlayer/add/

Django Version: 2.2.6 Python Version: 3.7.3 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.gis', 'raster', 'ras.apps.RasConfig'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\raster\tasks.py" in create_tiles

  1. parser.reproject_rasterfile()

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\raster\tiles\parser.py" in reproject_rasterfile

  1. dest_zip = zipfile.ZipFile(dest.name, 'w', allowZip64=True)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\zipfile.py" in init

  1. self.fp = io.open(file, filemode)

During handling of the above exception ([Errno 13] Permission denied: 'C:\Users\DELL\AppData\Local\Temp\tmpaadzqk14\tmpmp_6awy2.zip'), another exception occurred:

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\core\handlers\exception.py" in inner

  1. response = get_response(request)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\contrib\admin\options.py" in wrapper

  1. return self.admin_site.admin_view(view)(*args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\utils\decorators.py" in _wrapped_view

  1. response = view_func(request, *args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func

  1. response = view_func(request, *args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\contrib\admin\sites.py" in inner

  1. return view(request, *args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\contrib\admin\options.py" in add_view

  1. return self.changeform_view(request, None, form_url, extra_context)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\utils\decorators.py" in _wrapper

  1. return bound_method(*args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\utils\decorators.py" in _wrapped_view

  1. response = view_func(request, *args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\contrib\admin\options.py" in changeform_view

  1. return self._changeform_view(request, object_id, form_url, extra_context)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\contrib\admin\options.py" in _changeform_view

  1. self.save_model(request, new_object, form, not add)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\contrib\admin\options.py" in save_model

  1. obj.save()

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\db\models\base.py" in save

  1. force_update=force_update, update_fields=update_fields)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\db\models\base.py" in save_base

  1. update_fields=update_fields, raw=raw, using=using,

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\dispatch\dispatcher.py" in send

  1. for receiver in self._live_receivers(sender)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\django\dispatch\dispatcher.py" in

  1. for receiver in self._live_receivers(sender)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\raster\models.py" in parse_raster_layer_if_status_is_unparsed

  1. parse(instance.id)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\raster\tasks.py" in parse

  1. all_in_one(rasterlayer_id, zoom_range)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\celery\local.py" in call

  1. return self._get_current_object()(*a, **kw)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\celery\app\task.py" in call

  1. return self.run(*args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\raster\tasks.py" in all_in_one

  1. create_tiles(rasterlayer_id, zoom_range, True)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\celery\local.py" in call

  1. return self._get_current_object()(*a, **kw)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\celery\app\task.py" in call

  1. return self.run(*args, **kwargs)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\site-packages\raster\tasks.py" in create_tiles

  1. shutil.rmtree(parser.tmpdir)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\shutil.py" in rmtree

  1. return _rmtree_unsafe(path, onerror)

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\shutil.py" in _rmtree_unsafe

  1. onerror(os.unlink, fullname, sys.exc_info())

File "C:\Users\DELL\Anaconda3\envs\earth-analytics-python\lib\shutil.py" in _rmtree_unsafe

  1. os.unlink(fullname)

Exception Type: PermissionError at /admin/raster/rasterlayer/add/ Exception Value: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\DELL\AppData\Local\Temp\tmpaadzqk14\test.tif_copy.GTiff'

Yottox commented 4 years ago

Any solutions?

yellowcap commented 4 years ago

I don't have access to a Windows computer so I can't really debug this. It looks like the "closing" of a file from one function might not be registered properly and so the final removing of the intermediate files fails. Maybe when Celery tries to access it after the admin form uploaded it to the web server?

yellowcap commented 4 years ago

Could you try to run django-raster without celery (RASTER_USE_CELERY=False) https://django-raster.readthedocs.io/en/stable/settings.html#asynchronous-raster-parsing and see if it works that way just to see if its a celery related problem?

kshitijrajsharma commented 4 years ago

Still same problem occurs any solution found ? image

dksivagis commented 4 years ago

Hi, Any ideas how to solve this problem on windows. I am also stuck in the same problem. Help me how to to debug this issue.

kshitijrajsharma commented 4 years ago

Hi, Any ideas how to solve this problem on windows. I am also stuck in the same problem. Help me how to to debug this issue.

I shifted to ubuntu yet couldn't solve the issue

seema30fresher commented 2 years ago

Hi, I am also stuck with the same problem. Is anybody found the solution? image