У меня проблема с моим приложением Geo Django, и я думаю, что оно связано с отсутствующей переменной среды.
У меня следующая ошибка в простом GeoJSONLayerView:
GDALException at /GeoJSONTrialView/9020/
OGR failure.
Request Method: GET
Request URL: https://realregatta.com/GeoJSONTrialView/9020/
Django Version: 3.0.6
Exception Type: GDALException
Exception Value:
OGR failure.
Exception Location: /opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/gdal/error.py in check_err, line 59
Python Executable: /opt/bitnami/python/bin/python3
Python Version: 3.7.7
Я нашел обходной путь, добавив переменную среды в представление:
class GeoJSONTrialView(GeoJSONLayerView):
def get_queryset(self):
os.environ["PROJ_LIB"] = "/home/bitnami/stack/postgresql/share/proj"
context = Trial.objects.filter(id=self.kwargs['pk'])
return context
Обратите внимание, что у меня есть переменная, установленная в моем settings.py (и она отображается на странице Django debug cra sh, даже без моего обходного пути):
PROJ_LIB = "/home/bitnami/stack/postgresql/share/proj"
Traceback:
Environment:
Request Method: GET
Request URL: https://realregatta.com/GeoJSONTrialView/9020/
Django Version: 3.0.6
Python Version: 3.7.7
Installed Applications:
['RR.apps.AppConfig',
'djgeojson',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis']
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 (most recent call last):
File "/opt/bitnami/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/opt/bitnami/python/lib/python3.7/site-packages/djgeojson/views.py", line 89, in dispatch
return super(GeoJSONLayerView, self).dispatch(*args, **kwargs)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/views/generic/list.py", line 158, in get
return self.render_to_response(context)
File "/opt/bitnami/python/lib/python3.7/site-packages/djgeojson/views.py", line 79, in render_to_response
**options)
File "/opt/bitnami/python/lib/python3.7/site-packages/djgeojson/serializers.py", line 475, in serialize
self.end_serialization()
File "/opt/bitnami/python/lib/python3.7/site-packages/djgeojson/serializers.py", line 258, in end_serialization
json.dump(self.feature_collection, self.stream, cls=cls, **self.options)
File "/opt/bitnami/python/lib/python3.7/json/__init__.py", line 179, in dump
for chunk in iterable:
File "/opt/bitnami/python/lib/python3.7/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/opt/bitnami/python/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/opt/bitnami/python/lib/python3.7/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/opt/bitnami/python/lib/python3.7/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/opt/bitnami/python/lib/python3.7/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/opt/bitnami/python/lib/python3.7/site-packages/djgeojson/serializers.py", line 71, in default
return json.loads(o.geojson)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/geos/geometry.py", line 387, in json
return self.ogr.json
File "/opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/geos/geometry.py", line 429, in ogr
return gdal.OGRGeometry(self._ogr_ptr(), self.srs)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/geos/geometry.py", line 436, in srs
return gdal.SpatialReference(self.srid)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/gdal/srs.py", line 92, in __init__
self.import_epsg(srs_input)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/gdal/srs.py", line 277, in import_epsg
capi.from_epsg(self.ptr, epsg)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/gdal/prototypes/errcheck.py", line 117, in check_errcode
check_err(result, cpl=cpl)
File "/opt/bitnami/python/lib/python3.7/site-packages/django/contrib/gis/gdal/error.py", line 59, in check_err
raise e(msg)
Exception Type: GDALException at /GeoJSONTrialView/9020/
Exception Value: OGR failure.
Не уверен, что делать, чтобы избежать моего обходного пути ...