I have created a separate file test.py to interface with Azure Key Vault. When I run just the test.py file it works as expected. However, I cannot import it in settings.py for its values to be used there. I cannot import any file into settings.py for that matter or it causes an internal 500 error on Apache.
For instance I want to add these lines to my settings.py
import test
Pass = test.Pass
However, when adding that and restarting the Apache server is gives an error 500 page until I remove the lines and restart. test.py has no syntax errors because I can run it on its own and produce the result I am looking for but bringing any file into settings.py causes the crash. The error logs have been no help. Why would I not be able to import a file into settings.py?
The file I am importing is successful a part of the PYTHONPATH variable and I have checked that by printing sys.path. Also the file is located in the same directory as settings.py
mysite/
settings,py
test.py
urls.py
wsgi.py
init.py
The error from the server logs reads
ValueError: client_id should be the id of an Azure Active Directory application\r, referer: http://test.example.com/test/login/
However, this when I test the file individually it works as expected successfully connecting to Azure and doing the work it needs a retrieves and prints a correct password. This error is only caused when importing it in setting.py
CodePudding user response:
Not sure whether it works, but can you rename the file to __init__.py
in mysite
directory, and import test.py
like following
from mysite import test
CodePudding user response:
Whether absolute imports work depends on the directory the python interpreter is running from. I've had trouble with PYTHONPATH
before too. Have you tried from . import test
?