Permission error on live server

Hello,

I get the following error when trying to access a webpage in my WebApp:

" # PermissionError at /map/mapoverviewcollaborators

[Errno 13] Permission denied: ‘/usr/share/httpd/pgeocode_data’ "

Any idea how I can fix this? I can provide more information if needed.

Is /usr/share/httpd/pgeocode_data a URL within your application or a static file?

(Or is it a file being accessed directly by a view?)

What user/group is your application server running as? (Is it uwsgi, gunicorn, or something else?)

What are the permissions on that file? What are the user and group that own it?

Where are you seeing this error? Is this from a log file? If so, which one?

  1. It is not a URL in my application, I believe it’s a file/library that gets accessed by a view.
  2. This I don’t know
  3. If you mean the /usr/share/httpd/pgeocode_data file, I can’t seem to find this one on the live server.
  4. I’m seeing this on a webpage where I try to fetch latitude & longitude using the pgeo library for pinpointing exact locations and coloring them in combination with Leaflet library.

Something, somewhere is trying to access this file. You would need to determine what code is trying to access it, and what uid:gid that code is running as (assuming a Unix-style OS).

You then need to verify that if the file doesn’t exist in the identified location, where it does exist and modify the code to refer to the right location.
If the file does exist in that location, then you need to verify that the process trying to access it has permission to do so.

Hey I’ve located the folder, but like you said the file/folder isn’t there here is a picture for you to see:

Ok, that’s good to know.
Now you need to identify:

  • What is trying to access that file,
  • Why it’s trying to access it in that directory,
  • Where that file is actually located
    and change things appropriately.

The solution may be as simple as copying that file to that directory.

I can send you the full traceback:

Environment:

Request Method: GET
Request URL: https://visits.cloudspot.be/map/mapoverviewcollaborators

Django Version: 3.2.13
Python Version: 3.6.8
Installed Applications:
[‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘widget_tweaks’,
‘django_select2’,
‘dateutil’,
‘pgeocode’,
‘urllib3’,
‘geopy’,
‘main’]
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 “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/core/handlers/exception.py”, line 47, in inner
response = get_response(request)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/core/handlers/base.py”, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/views/generic/base.py”, line 70, in view
return self.dispatch(request, *args, **kwargs)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/views/generic/base.py”, line 98, in dispatch
return handler(request, *args, **kwargs)
File “/var/www/app_phytovetvisits/main/views.py”, line 846, in get
nomi = pgeocode.Nominatim(‘be’)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/pgeocode.py”, line 209, in init
self._data_path, self._data = self._get_data(country)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/pgeocode.py”, line 236, in _get_data
os.mkdir(STORAGE_DIR)

Exception Type: PermissionError at /map/mapoverviewcollaborators
Exception Value: [Errno 13] Permission denied: ‘/usr/share/httpd/pgeocode_data’

From the traceback it looks like this is likely an issue with a third-party library.

You can either dig into the source code of that library to understand what’s going on, or check their site / documentation / issues / etc to see if this is a known problem with an identified solution - and contact the maintainer(s) if it’s not.

Quickly scrolled through the documentation and found this. Might this be useful?

Could be.

I’m sorry, but I don’t know anything about that library. I’m not going to know whether any specific idea is going to work or not.

So the thing I had to do was basically download the required .TXT file from their Github and make the folder inside the /usr/share/httpd folder. Which I did and now I get a different error namely a KeyError, I’ll put the traceback down below.

Traceback:
Environment:

Request Method: GET
Request URL: https://visits.cloudspot.be/map/mapoverviewcollaborators

Django Version: 3.2.13
Python Version: 3.6.8
Installed Applications:
[‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘widget_tweaks’,
‘django_select2’,
‘dateutil’,
‘pgeocode’,
‘urllib3’,
‘geopy’,
‘main’]
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 “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/core/handlers/exception.py”, line 47, in inner
response = get_response(request)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/core/handlers/base.py”, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/views/generic/base.py”, line 70, in view
return self.dispatch(request, *args, **kwargs)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/django/views/generic/base.py”, line 98, in dispatch
return handler(request, *args, **kwargs)
File “/var/www/app_phytovetvisits/main/views.py”, line 846, in get
nomi = pgeocode.Nominatim(‘be’)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/pgeocode.py”, line 211, in init
self._data_frame = self._index_postal_codes()
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/pgeocode.py”, line 252, in _index_postal_codes
df_unique_cp_group = self._data.groupby(“postal_code”)
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/pandas/core/frame.py”, line 6525, in groupby
dropna=dropna,
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/pandas/core/groupby/groupby.py”, line 533, in init
dropna=self.dropna,
File “/var/www/env_phytovetvisits/lib/python3.6/site-packages/pandas/core/groupby/grouper.py”, line 786, in get_grouper
raise KeyError(gpr)

Exception Type: KeyError at /map/mapoverviewcollaborators
Exception Value: ‘postal_code’

This still looks like it’s related to that third-party package.

Your last line of code in this traceback is:

which (apparently) is creating an instance of an object named Nominatim. (Everything after this in the traceback is coming from the library.) Something in the creation of that object is causing the error.

Maybe I should just try n find another library then… This is super annoying tbh

I don’t understand why it works perfectly on a local build.