Closed Tony-Frank-ML closed 2 years ago
See:
https://modwsgi.readthedocs.io/en/master/user-guides/application-issues.html#application-working-directory https://modwsgi.readthedocs.io/en/master/user-guides/application-issues.html#application-working-directory
The issue is that you are using a relative path name rather than an absolute path name for the log file. As a consequence it is going to be written to the current working directory of the process, which will be root directory of the file system, which only root can write to. You need to calculate an absolute path name for the file to the derived location you want to write it.
Graham
On 27 Nov 2021, at 12:39 am, Tony-dot-Frank @.***> wrote:
I have a flask application running on a ubuntu server
I have tried to play around with other possible permission settings. I have tried setting the user 'www-data' as the owner of the folder using chown. Ive tried setting the ownerhsip of www-data using groups. Nothing seems to work.
-rw-rw-r-- 1 www-data www-data 3286 Nov 25 10:09 imm_migration.log
This is my Full error message
[Fri Nov 26 11:05:22.302892 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] mod_wsgi (pid=1453): Failed to exec Python script file '/home/admin/imm-migration/easyucs_api.wsgi'. [Fri Nov 26 11:05:22.302940 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] mod_wsgi (pid=1453): Exception occurred processing WSGI script '/home/admin/imm-migration/easyucs_api.wsgi'. [Fri Nov 26 11:05:22.303054 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] Traceback (most recent call last): [Fri Nov 26 11:05:22.303093 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.wsgi", line 8, in
[Fri Nov 26 11:05:22.303099 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] main() [Fri Nov 26 11:05:22.303105 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 225, in main [Fri Nov 26 11:05:22.303119 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] easyucs = Easyucs(logger_handle_log_level="debug", log_file_path="imm_migration.log") [Fri Nov 26 11:05:22.303127 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 38, in init [Fri Nov 26 11:05:22.303144 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] self._init_logger() [Fri Nov 26 11:05:22.303149 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 102, in _init_logger [Fri Nov 26 11:05:22.303154 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] fh = logging.FileHandler(self._log_file_path) [Fri Nov 26 11:05:22.303159 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/usr/lib/python3.8/logging/init.py", line 1143, in init [Fri Nov 26 11:05:22.303162 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] StreamHandler.init(self, self._open()) [Fri Nov 26 11:05:22.303167 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/usr/lib/python3.8/logging/init.py", line 1172, in _open [Fri Nov 26 11:05:22.303171 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] return open(self.baseFilename, self.mode, encoding=self.encoding) [Fri Nov 26 11:05:22.303186 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] PermissionError: [Errno 13] Permission denied: '/imm_migration.log' i have set the user and the owner to www-data to the whole working directory This is my apache conf
<VirtualHost *:80>
ServerAdmin ***@***.*** DocumentRoot /home/admin/imm-migration ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /home/admin/imm-migration> # set permissions as per apache2.conf file Options FollowSymLinks AllowOverride None Require all granted </Directory> WSGIDaemonProcess migration python-path=/home/admin/imm-migration LoadModule wsgi_module "/usr/local/lib/python3.8/dist-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so" WSGIScriptAlias / /home/admin/imm-migration/easyucs_api.wsgi WSGIApplicationGroup %{GLOBAL} WSGIProcessGroup migration WSGIPassAuthorization On
python version 3.8
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GrahamDumpleton/mod_wsgi/issues/737, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD355KS36NFNCMR5URWHDTUN6EZTANCNFSM5I2WCDNQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Hi Graham, Thanks for the reply
I have tried providing absolute path for the log file too. Still facing the error
[Fri Nov 26 21:24:41.875712 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.105:57686] easyucs = Easyucs(logger_handle_log_level="debug", log_file_path="/home/admin/imm-migration/imm_migration.log")
Full error message
[Fri Nov 26 11:05:22.302892 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] mod_wsgi (pid=1453): Failed to exec Python script file '/home/admin/imm-migration/easyucs_api.wsgi'.
[Fri Nov 26 11:05:22.302940 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] mod_wsgi (pid=1453): Exception occurred processing WSGI script '/home/admin/imm-migration/easyucs_api.wsgi'.
[Fri Nov 26 11:05:22.303054 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] Traceback (most recent call last):
[Fri Nov 26 11:05:22.303093 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.wsgi", line 8, in <module>
[Fri Nov 26 11:05:22.303099 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] main()
[Fri Nov 26 11:05:22.303105 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 225, in main
[Fri Nov 26 11:05:22.303119 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] easyucs = Easyucs(logger_handle_log_level="debug", log_file_path="/home/admin/imm-migration/imm_migration.log")
[Fri Nov 26 11:05:22.303127 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 38, in __init__
[Fri Nov 26 11:05:22.303144 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] self._init_logger()
[Fri Nov 26 11:05:22.303149 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 102, in _init_logger
[Fri Nov 26 11:05:22.303154 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] fh = logging.FileHandler(self._log_file_path)
[Fri Nov 26 11:05:22.303159 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/usr/lib/python3.8/logging/__init__.py", line 1143, in __init__
[Fri Nov 26 11:05:22.303162 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] StreamHandler.__init__(self, self._open())
[Fri Nov 26 11:05:22.303167 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/usr/lib/python3.8/logging/__init__.py", line 1172, in _open
[Fri Nov 26 11:05:22.303171 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] return open(self.baseFilename, self.mode, encoding=self.encoding)
[Fri Nov 26 11:05:22.303186 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] PermissionError: [Errno 13] Permission denied: '/imm_migration.log'
What do you get for:
ls -lasd /home/admin/imm-migration
ls -lasd /home/admin/imm-migration
4 drwxrwxr-x 25 www-data www-data 4096 Nov 26 21:23 /home/admin/imm-migration
If the log still shows:
[Fri Nov 26 11:05:22.303171 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] return open(self.baseFilename, self.mode, encoding=self.encoding)
[Fri Nov 26 11:05:22.303186 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] PermissionError: [Errno 13] Permission denied: '/imm_migration.log'
then you can't be setting the path in the correct location as it still shows /imm_migration.log
.
Ensure you do a full stop/start of Apache to ensure your modified code is being picked up.
BTW, your configuration has:
LoadModule wsgi_module "/usr/local/lib/python3.8/dist-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so"
inside of the VirtualHost
. Apache should error on that and not even start. So I question whether that config is even being used.
But earlier i managed to bring up the UI of the application..Is there any way to check if the config is being used
What is the full path name to that Apache config file? If it is in a sites-available
directory if using debian/ubuntu, ensure that the same named file in sites-enabled
directory is actually a symlink to it and not a copy. Maybe you managed to create a copy to sites-enabled
instead and so Apache is using separate copy.
As to checking if in use, add something which is an obvious error in the file, such as:
ThisDirectiveDoesNotExist
Apache should fail to start if that file is being read.
The apache failed to start once i added something wrong in configration...seems the config is being used
If the log still shows:
[Fri Nov 26 11:05:22.303171 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] return open(self.baseFilename, self.mode, encoding=self.encoding) [Fri Nov 26 11:05:22.303186 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] PermissionError: [Errno 13] Permission denied: '/imm_migration.log'
then you can't be setting the path in the correct location as it still shows
/imm_migration.log
.Ensure you do a full stop/start of Apache to ensure your modified code is being picked up.
BTW, your configuration has:
LoadModule wsgi_module "/usr/local/lib/python3.8/dist-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so"
inside of the
VirtualHost
. Apache should error on that and not even start. So I question whether that config is even being used.
So i rebooted the machine and the permission error no longer exist. For some reason my modified code is didnt picked up
I added something which is error im my configration and the apache threw error. Seems like the config is even used.
Okay, that's odd, never noticed that before.
https://httpd.apache.org/docs/2.4/mod/mod_so.html#loadmodule
This says that LoadModule can be used inside of a VirtualHost definition. Not sure why they would want to allow that since it isn't going to be isolated to the VirtualHost.
Anyway, it is more conventional to have it outside of VirtualHost and on debian/ubuntu is usually loaded from a file in a mods-available directory.
Anyway, sounds like the path issue is fixed at least.
Yes Graham the path issue is fixed..appreciate your help so much.Thank you
PermissionError PermissionError: [WinError 5] Access is denied
Traceback (most recent call last)
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 2551, in call
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 2531, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 2528, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 1823, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 1799, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(*view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\USER\OneDrive\Desktop\EE project\EEpy.py", line 26, in home
text = tess.image_to_string(Image.open(filename))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pytesseract\pytesseract.py", line 423, in image_to_string
return {
^^^^^^^^^
File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pytesseract\pytesseract.py", line 426, in
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection
I have a flask application running on a ubuntu server
I have tried to play around with other possible permission settings. I have tried setting the user 'www-data' as the owner of the folder using chown. Ive tried setting the ownerhsip of www-data using groups. Nothing seems to work.
-rw-rw-r-- 1 www-data www-data 3286 Nov 25 10:09 imm_migration.log
This is my Full error message
i have set the user and the owner to www-data to the whole working directory
This is my apache conf
python version 3.8