Forbidden 403 You don't have permission to access this resource.

Trying to log into webserver the first time right after install, I get the following error message:
Forbidden 403
You don't have permission to access this resource.

Apache/2.4.52 (Ubuntu) Server at 172.105.13.229 Port 80

sudo tail -f /var/log/apache2/error.log Gave me the following error log. (exactly the same for “warn or “”debug”)

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007f433bc20780 (most recent call first):
<no frame="" python="">
[Sun Oct 29 15:59:32.376457 2023] [wsgi:warn] pid 187461:tid 139926742108032Permission denied: mod_wsgi (pid=187461): Unable to stat Python home /home/jsandor/src/venv. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Python path configuration:
PYTHONHOME = '/home/jsandor/src/venv'
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/bin/python3'
sys.base_prefix = '/home/jsandor/src/venv'
sys.base_exec_prefix = '/home/jsandor/src/venv'
sys.platlibdir = 'lib'
sys.executable = '/usr/bin/python3'
sys.prefix = '/home/jsandor/src/venv'
sys.exec_prefix = '/home/jsandor/src/venv'
sys.path = [
'/home/jsandor/src/venv/lib/python310.zip',
'/home/jsandor/src/venv/lib/python3.10',
'/home/jsandor/src/venv/lib/python3.10/lib-dynload',
]
Could any one help me to solve this problem?
Thanks.</no>

5 Replies

A 403 Forbidden error is generally a permissions issue on one of your files or directories. This post titled <no frame="" python=""> error while trying to connect to apache on mod_wsgi in Ubuntu</no> addresses the same wsgi:warn error you are seeing. The solution was as follows was to change the permissions on the user's home directory:

sudo chmod 755 /home/<user>

I can see when I open your IP address in my browser that the page loads without a 403 error so it looks like your issue is resolved as well. Hopefully it didn't take you too long to figure out!

Thank you for your help. I did change the chmod, and the homepage loads, but when I click on any of my links the server times out.
These are my file permissions:
jsandor@django-server:~$ ls -la
total 36
drwxr-xr-x 5 jsandor jsandor 4096 Oct 30 16:36 .
drwxr-xr-x 3 root root 4096 Oct 28 02:02 ..
-rw------- 1 jsandor jsandor 2377 Nov 1 04:40 .bash_history
-rw-r--r-- 1 jsandor jsandor 220 Oct 28 02:02 .bash_logout
-rw-r--r-- 1 jsandor jsandor 3771 Oct 28 02:02 .bashrc
drwx------ 3 jsandor jsandor 4096 Oct 28 02:31 .cache
-rw-r--r-- 1 jsandor jsandor 807 Oct 28 02:02 .profile
drwxrwxr-x 8 jsandor www-data 4096 Oct 30 16:36 src
drwx------ 2 jsandor jsandor 4096 Oct 28 02:10 .ssh
-rw-r--r-- 1 jsandor jsandor 0 Oct 28 02:11 .sudo_as_admin_successful
jsandor@django-server:~$ cd src
jsandor@django-server:~/src$ ls -la
total 184
drwxrwxr-x 8 jsandor www-data 4096 Oct 30 16:36 .
drwxr-xr-x 5 jsandor jsandor 4096 Oct 30 16:36 ..
drwxrwxr-x 6 jsandor jsandor 4096 Oct 28 02:25 blog
-rw-rw-r-- 1 jsandor www-data 147456 Oct 28 02:25 db.sqlite3
drwxrwxr-x 3 jsandor jsandor 4096 Oct 29 23:38 django_project
-rwxrwxr-x 1 jsandor jsandor 670 Oct 28 02:25 manage.py
drwxrwxr-x 3 jsandor www-data 4096 Oct 28 02:25 media
-rw-rw-r-- 1 jsandor jsandor 136 Oct 28 02:25 requirements.txt
drwxrwxr-x 4 jsandor jsandor 4096 Oct 28 02:42 static
drwxrwxr-x 5 jsandor jsandor 4096 Oct 28 02:25 users
drwxrwxr-x 5 jsandor jsandor 4096 Oct 28 02:29 venv

These are the settings for Apache Server:

     Alias /static /home/jsandor/src/static
     <Directory /home/jsandor/src/static>
             Require all granted
     </Directory>

     Alias /media /home/jsandor/src/media
     <Directory /home/jsandor/src/media>
             Require all granted
     </Directory>

     <Directory /home/jsandor/src/django_project>
             <Files wsgi.py>
                     Require all granted
             </Files>
     </Directory>

     WSGIScriptAlias / /home/jsandor/src/django_project/wsgi.py
     WSGIDaemonProcess django_app python-path=/home/jsandor/src python-home=/home/jsandor/src/venv>
     WSGIProcessGroup django_app

Do you see anything that should be changed?
Thanks.

When I try to load the links on your site, I see an Internal Server Error message that also says:

"More information about this error may be available in the server error log."

I get a similar response when I run a curl to one of your link urls:

$ curl -sIL http://172.105.13.229/post/4/
HTTP/1.1 500 Internal Server Error
Date: Wed, 01 Nov 2023 18:30:35 GMT
Server: Apache/2.4.52 (Ubuntu)
Connection: close
Content-Type: text/html; charset=iso-8859-1

This post titled How do I get rid of a 500 Internal Server Error with apache and django shares a resource on checking your server's log files as well as making some changes to wsgi.py file.

Also, you should take efforts to obscure specific information about your server like the IP address and the file structure. Bad actors could easily get that information and attempt to gain access to your instance for nefarious purposes.

Thank you for the info and thank you for the warnings. I am very new at this and probably more trusting than I should be.
Also, I get this from the error log:
Truncated or oversized response headers received from daemon process 'django_app':
What does this mean?

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct