-->

Errno 13 Permission denied with Django on a direct

2019-07-12 02:30发布

问题:

I have this error appearing in my Django app on my production server :

[Errno 13] Permission denied: '/var/www/.config'

I never asked to access to this unexisting file or directory in my code. The server is running in a different directory defined in my httpd.conf and I haven't defined the use of any /var/www/ elements in my Django settings.

In my case I'm using the biopython library with Django :

from Bio import Entrez

Entrez.email = "my@email"

handle = Entrez.efetch("taxonomy", id="123, 1")
records = Entrez.parse(handle)

This code is working in a python console on the server. But the instruction Entrez.parse(handle) return the error in a Django environment.

I haven't seen any instruction asking to write or open anything in the source code of the function so it seems to be a problem with Django?

Is it a configuration problem? A background Django function trying to access to a file when I call a specific function?

My configuration :

  • Python 3.3
  • Django 1.8
  • Biopython 1.67

回答1:

In facts, Entrez.parse is calling the DataHandler objects. This objects try to write in the user directory with something like :

home = os.path.expanduser('~')
directory = os.path.join(home, '.config', 'biopython')
local_xsd_dir = os.path.join(directory, 'Bio', 'Entrez', 'XSDs')
os.makedirs(local_xsd_dir)

Because biopython user is the httpd user, the home directory is /var/www/.

The solution is here to allow apache to write into /var/www or to move it to a different place.



回答2:

Restart the server or restart the service of django.
That is important, because the services in the background have to know the new location of the configuration.
I guess it works on python, because the library is loading the actual settings and the background service is using the old one.

Hope I could help