Error Running WSGI application - client_secrets.json - python

I´m making a web app with django, but when I run the application, I´m getting this error:
I have uploaded my client_secrets.json file in the project path and I´m sure I have no typos
Settings.py
GOOGLE_OAUTH2_CLIENT_SECRETS_JSON = 'client_secrets.json'
WSGI.py
# This file contains the WSGI configuration required to serve up your
# web application at http://bohosul02.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# The below has been auto-generated for your Django project
import os
import sys
# add your project directory to the sys.path
project_home = '/home/bohosul02/misitio'
if project_home not in sys.path:
sys.path.insert(0, project_home)
# set environment variable to tell django where your settings.py is
os.environ['DJANGO_SETTINGS_MODULE'] = 'gfglogin.settings'
# serve django via WSGI
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

You're using a relative path name (client_secrets.json) without paying attention to what your working directory is. If you use the full path to the file, then it will be able to find it.

Related

Django's "check" cannot import settings

Since the project is evolving I would like to start executing the system check framework of Django on dev environment. The technology stack is Ubuntu, PostgreSQL, Django1.9 + UWSGI. But...
django-admin check
outputs the following error:
ImportError: No module named my_project.settings
The wsgi.py file contains:
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('~/virtenv/my_site')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_site.settings")
application = get_wsgi_application()
The env variable DJANGO_SETTINGS_MODULE echoes my_site.settings
It is important to mention that the settings.py file is in virtenv/my_site/my_site/ . Please also note that the entire web application is running fine, I am also using the features of manage.py. Its just the django-admin check that is getting on my nerves.
you seem to append to the sys path in the wsgi but the admin check won't be using that.
Make sure you add the project path to the sys path for the environment you're using

Hosting Django with passenger_wsgi.py

I'm having trouble setting up my django on dreamhost shared hosting using python passenger_wsgi.py and virtual env. When I run passenger_wsgi.py no error is returned and the shell prints my project path. My website shows a 500 International server error. I have cleared my cache so there is no cache error. How do I set this up properly?
django 1.9
python 2.7
apache
My site structure is:
/home/myuser/mydomain.com/
env/
myApp/
passenger_wsgi.py
public/
passenger_wsgi.py
import sys, os
cwd = os.getcwd()
sys.path.append(cwd)
project_location = cwd + '/myApp'
print (project_location)
sys.path.insert(0, project_location)
#Switch to new python
if sys.version < "2.7.3": os.execl("/home/myuser/mydomain.com/env/bin/python",
"python2.7.3", *sys.argv)
sys.path.insert(0,'/home/myuser/mydomain.com/env/bin')
sys.path.insert(0,'/home/myuser/mydomain.com/env/lib/python2.7/site-packages/django')
sys.path.insert(0,'/home/myuser/mydomain.com/env/lib/python2.7/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = "myApp.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I had issues with Dreamhost specifically when upgrading from Django 1.6 to 1.8. One of the issues was with the WSGIHandler(). I can't say this is your problem specifically, but you can try setting application like this:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Finally - make sure you restart passenger. There are docs here about how to do it: http://wiki.dreamhost.com/Passenger
From that page:
Whenever the code or configuration files for your application are modified, you must create or update the modification date of the file "tmp/restart.txt" in the application's root directory tree in order to trigger Passenger to reinitialize the application. Passenger caches many resources so changes are not recognized unless the modification date of "tmp/restart.txt" is changed.
The most common method to make this change is to run "touch tmp/restart.txt" via SSH. (Ruby on Rails automatically creates a directory named "tmp". If you are creating non-RoR application, you may need to create the "tmp" directory manually.

How do I get all files for my django app into one folder?

I currently have a Django app named reserve. In the folder named "reserve" I have most of the content of my app (views.py, urls.py, models.py, templates folder). However, I have a folder outside of "reserve" named "booking" that has only my settings.py. I tried consolidating by putting the settings.py in "booking" into "reserve" but I seem to be getting an error. Any advice on how to have only one folder with all contents?
The error I get is: ImportError: Could not import settings 'booking.settings' (Is it on sys.path?): No module named booking.settings
overall project folder
booking folder
settings.py
init.py
reserve folder (the app)
views.py
admin.py
models.py
...
what version of django are you using? what command are you running ? assuming that you are just trying to run a command using manage.py you could just chnage manage.py to reflect this if you are going to permanently keep this project structure
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
you should change os.environ.setdefault to the correct directory for your settings.py
I'm assuming you have manage.py at the overal project directory? I'm also assuming you want to just runserver.
It seems you moved the settings.py file outside the overal project directory. If you do this, you'll have to specify the settings file path when you do runserver, or you can also export the django settings module to point to your new settings path (using dot notation). In this case, I think it would be (in the command line):
export DJANGO_SETTINGS_MODULE=<overal-project-folder-name>.booking.settings
python manage.py runserver

Apache loads x.wsgi file from django project, no __file__ attribute associated

I am trying to load a python wsgi file called from apache with mod_wsgi. My wsgi file attempts to reset the sys.path with:
import os, sys
root = os.path.join(os.path.dirname(__file__), '..')
sys.path.insert(0, root)
Apache complains with:
[Wed Feb 15 19:12:26 2012] [error] [client 127.0.0.1]
ImportError: Could not import settings 'mysite.settings'
(Is it on sys.path?): No module namedmysite.settings`
when I do:
>>> dir('mysite.wsgi')
It becomes apparent the wsgi file does not possess the __file__ attribute, so my sys.path is not getting updated with the necessary directory.
Why would this mysite.wsgi file not have a __file__ attribute?
It should work,
but you can also try and check if following code block helps.
DIRNAME = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(DIRNAME)
The resulting path set to 'root', must be the parent directory of the directory where the Django settings.py is located and 'mysite' must be the name of that directory. You say nothing about the name of your project directory or where the WSGI file is located with respect to it, so not possible to tell you how your code is wrong.
Code under Apache will also run as special user, so project directory must be accessible/readable to that user.
Perhaps go watch:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
to better understand how to set it all up.

Deploying Pyramid to dotcloud

What is the proper way to deploy a Pyramid project to dotcloud?
The contents of wsgi.py:
import os, sys
from paste.deploy import loadapp
current_dir = os.path.dirname(__file__)
application = loadapp('config:production.ini', relative_to=current_dir)
I'm currently getting the following error.
uWSGI Error
wsgi application not found
This could indicate that wsgi.py could not be imported successfully.
You can check the following:
output of dotcloud logs appname.servicename
log into the service with dotcloud ssh appname.servicename, then go to the current directory, start python and see what happens if you try to do from wsgi import application
If that can help, here is a super-simple Pyramid app:
https://github.com/jpetazzo/pyramid-on-dotcloud
I was able to get pass the uWSGI Error error using :
import os
from paste.deploy import loadapp
current_dir = os.getcwd()
application = loadapp('config:production.ini', relative_to=current_dir)
I still had a path problem with the static files so I changed:
config.add_static_view('static', 'static', cache_max_age=3600)
to
config.add_static_view('<myapp>/static', 'static', cache_max_age=3600)
try this:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'hellodjango.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
http://docs.dotcloud.com/tutorials/python/django/

Categories