Permission denied when django writes to external device - python

I have a django file server. The server works perfectly on my laptop & localhost (with external hard drive) but when I transferred it to my Raspberry Pi running Raspbian, it starts acting up.
I did a lot of googling and tried every possible solution but it does not work.
Here is my problem:
I have connected an external hard drive to my raspberry pi. I believe it has write permissions because I can easily write to it with mkdir. I have also set this directory which is /media/pi/SAMSUNG/media as my MEDIA_ROOT.
Now I have set up Apache2, WSGI and Django, everything works, I have set up all the permissions and everything, but still when django tries to access the hard drive, whether it be to read or write, I get an error [Errno 13] Permission denied: '/media/pi/SAMSUNG'.
I have fixed this in the past with chown -R 777 but it does not work this time.
Unfortunetly, I have no idea what I am doing when it comes to servers and file permissions, so I have no idea what code to attach. Can some please help me?
I will attach all the necessary code on request.
Thank you

On raspbian you have to be careful when using external drives. Have you edited the file /etc/fstab? This is necessary to mount the drive also correctly after restarts and when the file is temporarily disconnected and then connected again.
If you did this correctly, then the drive will have the permissions you gave it when mounting and Django should be able to access it/write to it.
BR

Related

APK file is crashing when I access mysql database

I can access MySQL on my other laptops at home, but when I converted my py file to apk, my app crashed when I hit the button connected to my database. I put my computer IP (host) in the code and gave all privilege grants to that user. I have also given permission to the internet in the buildozer.spec file. Still my application is crashes, what should I do?
I tried accessing mysql data to my other computers at home they work fine, but here I am creating an applications with kivy python its crash when I try to access database. I am using IP address to connect to data base and also check that there is not firewall. I am using macbook air and trying to run my apk file into one plus which is running android 12.
Link for my all code & [android debug file]
https://github.com/kushp15/PY-to-APK
There you have your error
And the solution to it is providing mysql-connector-python in buildozer requirements.
There has been a similar issue.
Instead of using mysql_connector_python, I switch to pymysql which worked correctly, and in buildozer instead of mysql_connector change to pymysql. Thats it, It works. I have updates on my github page. Link: https://github.com/kushp15/PY-to-APK

Unable to create process

I updated my python version and when I try to run server on prompt for django I get this error.
Unable to create process using 'C:\Users\ALFRED\AppData\Local\Programs\Python\Python311\python.exe
manage.py runserver': The system cannot find the file specified.
This error occurs when the file system of the target device is corrupted or damaged, making your hard drive, USB or external hard drive inaccessible.
Are you sure you typed the right command python manage.py runserver.

Access local directory files from a flask api running on docker container

My API has to access an image located in a directory on the host server, store it in another directory and access the whole directory multiple times in the host server.
Currently, when I run the API on docker container and it tries to access an image present in a directory on the host, I get the error-
FileNotFoundError: [Errno 2] No such file or directory: 'W:/datasets/tmp/users/1.jpg'
I understand this is because the API is running on an independent server. The directory cannot be mounted to the container as it is large and also will keep increasing in real-time.
How do I access the file system in this situation?
Will SSH using paramiko help in this case or is there another way to do it?
Will SSH using paramiko help in this case
No, you want a file server, not a shell. If you had an SSH server on the host, then you could use SFTP, but you could also use NFS, as commented
Ultimately, if you're trying to access directories on the same machine as the container, you should be using volume mounts into the container
cannot be mounted to the container as it is large and also will keep increasing in real time.
So? Have you tried using the mount? What specific issues were you having with it "being large" and mounted?

Adding read/write permission to access external HD under Catalina

I'm working on MAC application contains a command line tool.
The GUI (electron) using sudo prompt to run the command line tool written in Python.
Under Catalina, the app all needed permission to w/r for the protected directories like Desktop with no issue.
Needed permission request were added to plist and it is signed with list of entitlements.
All works well except accessing external hard drive. Any try to create folder or modifying its properties using chmod command for example return with permission denied.
Just for note, calling same command from terminal ends well with no issue
Any ideas how I can go over it?
How App can request Full disk access?

Python script can't write file

I have a Flask app hosted on a Linode server. I have a script to fetch a json and write it to a file. When I run this script getprice.py on my server I get the error [Errno 13] Permission denied: 'app/static/prices.json. It works fine on my local machine though. What do I have to do to get it working?
The answer is in your question. The user your script is running as on the server doesn't have write permissions on 'app/static'. It may be helpful if you also posted the getprice.py code, but it seems like a pretty straightforward file permission problem.

Categories