Where is "hellodjango.wsgi"? - django

I'm trying to assemble some of the missing pieces in my understanding of how to deploy a Django App to heroku, so that I can launch an instance of Newsdiffs on Heroku.
When I walk through the instructions for running Django on Heroku they have you add a line to Procfile that reads thus: web: gunicorn hellodjango.wsgi --log-file -
But there's no actual file named "hellodjango.wsgi" so ... in that tutorial, where is the "hellodjango.wsgi" module created?
And, perhaps more to the point, why is heroku local balking that I have web.1 | : No module named newsdiffs.wsgi when newdsdiffs/wsgi.py definitely exists.
I can launch the app locally with python website/manage.py runserver but if I do gunicorn newsdiffs.wsgi I get the following, which doesn't include any obvious indications (to my eye) of what I'm doing wrong:
(venv)amanda#mona:newsdiffs$ gunicorn newsdiffs.wsgi
Traceback (most recent call last):
File "/home/amanda/Public/newsdiffs/venv/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
super(Application, self).run()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
Arbiter(self).run()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
self.manage_workers()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
self.spawn_workers()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 542, in spawn_workers
time.sleep(0.1 * random.random())
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
self.reap_workers()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

The gunicorn command takes the name of a Python module, not a path to a file. If hellodjango.wsgi is the name of the Python module, the corresponding file will be hellodjango/wsgi.py or hellodjango/wsgi/__init__.py.
This is the same syntax used to refer to a module when importing it, e.g. you would import * from hellodjango.wsgi to get access to the things defined in hellodjango/wsgi.py.
The django-admin startproject command will create a wsgi.py file in the same directory as the project's settings.py and urls.py files.

Related

Failed Manage.py runserver command

I'm a beginner in web development. I'm using pycharm and django 2.1 framework
I installed django using ('py -m pip install django==2.1') and it is done.
I started myweb project using ('py -m django-admin startproject myweb .') and it also done
but when I try ('manage.py runserver') command, this is the result:
(venv) C:\Users\مرحبا\PycharmProjects\Myweb>manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 27, 2020 - 20:08:58
Django version 3.0.4, using settings 'myweb.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread <bound method Thread.name of <Thread(django-main-thread,
started
daemon 5152)>>:
Traceback (most recent call last):
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 917, in
_bootstrap_inner
self.run()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\management\commands\runserver.py", line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 206, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 67, in __init__
super().__init__(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socketserver.py", line 449, in
__init__
self.server_bind()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\wsgiref\simple_server.py", line
50,
in server_bind
HTTPServer.server_bind(self)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\http\server.py", line 139, in
server_bind
self.server_name = socket.getfqdn(host)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socket.py", line 680, in getfqdn
aliases.insert(0, hostname)
AttributeError: 'str' object has no attribute 'insert'
Could you help me please?
In the last line of the error it says
aliases.insert(0, hostname) AttributeError: 'str' object has no attribute 'insert'
Your Aliases variables is a string, not a list, so you can't .insert() to it, as that functionality doesn't exist.
You need to make sure Aliases is a list in your code.

Fix Celery Issue 'can't pickle <class 'module'>: attribute lookup module on builtins failed

I am running celery 4.1.1 on windows and sending requests to redis(on ubuntu), Redis is properly connected and tested from windows side. But when i run this command
celery -A acmetelbi worker --loglevel=info
i get this long error:
[tasks]
. accounts.tasks.myprinting
. acmetelbi.celery.debug_task
[2019-08-02 11:46:44,515: CRITICAL/MainProcess] Unrecoverable error:
PicklingErr
or("Can't pickle <class 'module'>: attribute lookup module on builtins
failed",)
Traceback (most recent call last):
File "c:\acmedata\virtualenv\bi\lib\site-
packages\celery\worker\worker.py", line 205, in start
self.blueprint.start(self)
File "c:\acmedata\virtualenv\bi\lib\site-packages\celery\bootsteps.py",
line 119, in start step.start(parent)
File "c:\acmedata\virtualenv\bi\lib\site-packages\celery\bootsteps.py",
line 370, in start return self.obj.start()
File "c:\acmedata\virtualenv\bi\lib\site-
packages\celery\concurrency\base.py",
line 131, in start self.on_start()
File "c:\acmedata\virtualenv\bi\lib\site-
packages\celery\concurrency\prefork.p
y", line 112, in on_start
**self.options)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\pool.py", line
1007 , in __init__ self._create_worker_process(i)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\pool.py", line
1116, in _create_worker_process w.start()
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\process.py",
line 124, in start self._popen = self._Popen(self)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\context.py",
line 383, in _Popen return Popen(process_obj)
File "c:\acmedata\virtualenv\bi\lib\site-
packages\billiard\popen_spawn_win32.py",
line 79, in __init__ reduction.dump(process_obj, to_child)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\reduction.py",
line 99, in dump ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup
module on builtins failed
(bi) C:\acmedata\bi_solution\acmetelbi>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\spawn.py",
line 165, in spawn_main exitcode = _main(fd)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\spawn.py",
line 207, in _main self = pickle.load(from_parent)
EOFError: Ran out of input
i am scratching my head and unable to understand how to fix this. Please help!
my Code for creating a task in django app.
#task()
def myprinting(self):
print("I am task")
and in settings.py :
Other Celery settings
CELERY_BEAT_SCHEDULE = {
'task-number-one': {
'task': 'accounts.tasks.myprinting',
'schedule': crontab(minute='*/30'),
},
after spending many days in research i have come to conclusion that celery have limitation on windows and if you want to run celery on windows then you must have to run it with gevent command:
python manage.py celery worker -P gevent --loglevel=INFO
and then after running this worker process start the celery beat accordingly to start processing.

Problem when starting gunicorn with .sh (No module named '.0')

I'm trying to start a flask application with gunicorn but i'm facing an issue.
When starting it from command line it works fine with this command:
/usr/local/bin/gunicorn --preload --certfile /etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile /etc/letsencrypt/live/server_name.net/privkey.pem -w 17
-b 0.0.0.0:9090 wsgi:app
The same command from a .sh script raise an error :
Traceback (most recent call last):
File "/usr/local/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 61, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 221, in run
super(Application, self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 70, in run
Arbiter(self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 118, in setup
self.app.wsgi()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 65, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/util.py", line 372, in import_app
__import__(module)
ImportError: No module named '.0'
Both cli and .sh are run as root.
The same script works fine on a different server so i guess there is a problem with the environment.
I tried to add in the script the following lines at the beginning of the script without success:
$PYTHONPATH=/path/to/my/app
and
$PWD=/path/to/my/app
This is the wsgi file i'm using:
from api import app
if __name__ == "__main__":
app.run()
Any idea what the problem could be?
I was finally able to solve this problem. The following script seems to be working:
cd /path_to_app/
gunicorn --certfile=/etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile=/etc/letsencrypt/live/server_name.net/privkey.pem -w 4 -b 0.0.0.0:9090 wsgi:app

Gunicorn Django [CRITICAL] WORKER TIMEOUT

Since I did a pip install google-api-python-client I have my Gunicorn workers stoping after timeout.
Django==1.5.3
Gunicorn==0.12.2
I'm not really sure if it comes from the pip but I did nothing particular except a database migration which migrated without error.
I use this command for Gunicorn:
gunicorn_django myapp.py --bind 127.0.0.1:8181 --timeout 120 --log-file /tmp/myapp.gunicorn.log --log-level info --workers 8 --pid /tmp/myapp.pid
I tryed the param --spew to have some trace but it doesn't help me:
[2016-06-13 21:09:52 +0000] [15602] [INFO] Worker exiting (pid: 15602)
[2016-06-13 21:09:52 +0000] [15601] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 106, in load
return mod.make_wsgi_application()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 37, in make_wsgi_application
if get_validation_errors(s):
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/myapp/prod/apps/admin/models.py", line 5, in <module>
from django.contrib.auth.models import User
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/contrib/auth/models.py", line 18, in <module>
from django.contrib.auth.hashers import (
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/contrib/auth/hashers.py", line 8, in <module>
from django.test.signals import setting_changed
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/test/__init__.py", line 6, in <module>
from django.test.testcases import (TestCase, TransactionTestCase,
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/test/testcases.py", line 35, in <module>
from django.test import _doctest as doctest
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/django/test/_doctest.py", line 104, in <module>
import unittest, difflib, pdb, tempfile
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/pdbpp-0.7.2-py2.7.egg/pdb.py", line 38, in <module>
pdb = import_from_stdlib('pdb')
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/pdbpp-0.7.2-py2.7.egg/pdb.py", line 35, in import_from_stdlib
mydict = execfile(pyfile, result.__dict__)
File "/usr/local/lib/python2.7/pdb.py", line 3, in <module>
"""A Python debugger."""
File "/usr/local/lib/python2.7/pdb.py", line 3, in <module>
"""A Python debugger."""
File "/home/myapp/.local/share/virtualenvs/myapp/lib/python2.7/site-packages/gunicorn/debug.py", line 40, in __call__
line = src[lineno]
IndexError: tuple index out of range
[2016-06-13 21:09:52 +0000] [15601] [INFO] Worker exiting (pid: 15601)
As the problem came in the same time I installed google api client, I suspect pip to have upgraded some libs that are not compatible with my gunicorn or Django. I checked the pip log without success also.
If I run my Django app with runserver I can't see any bug, it seems very related to Gunicorn.
Is there a deeper way to debug Gunicorn ?
After struggling hours I finally found a clue in the pip log (HOME/.pip/pip.log) .
Installing google api client upgraded some of my previous libs like these:
Installing collected packages: pyopenssl, six, cryptography, idna, pyasn1, setuptools, enum34, ipaddress, cffi, pycparser
Found existing installation: pyOpenSSL 0.14
Uninstalling pyOpenSSL:
...
Found existing installation: six 1.9.0
Uninstalling six:
...
Found existing installation: cryptography 0.7.1
Uninstalling cryptography:
I noticed also some installing warning for cyptography. I decided to put back the old libs.
pyOpenSSL 0.14
six 1.9.0
cryptography 0.7.1
And it solved the problem. I don't know if it is pyopenssl or cryptography but it is getting really boring to have all these libs problems.
Hope this will help someone next time.

gunicorn_django -b 0.0.0.0 project_name/settings/production.py

$ python manage.py run_gunicorn 0.0.0.0:80 --settings=project_name.settings.production
<- It's run, OK.
but,
$ gunicorn_django -b 0.0.0.0:80 project_name/settings/production.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 106, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/djangoapp.py", line 102, in load
return mod.make_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/django_wsgi.py", line 36, in make_wsgi_application
if get_validation_errors(s):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 94, in load_app
app_module = import_module(app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
> ImportError: No module named accounts
2013-06-29 01:56:53 [30859] [INFO] Worker exiting (pid: 30859)
2013-06-29 01:56:53 [30854] [INFO] Shutting down: Master
2013-06-29 01:56:53 [30854] [INFO] Reason: Worker failed to boot.
How can I solve this problem?
I want to run on daemon.
Thanks.
This looks like an issue related to your PYTHONPATH. Try adding the path that contains the accounts module to your python path, using gunicorn's --pythonpath.
If you have newer gunicorn/Django versions using gunicorn via management command should be the preffered way - and it should be more safe regarding issues like this.
Try running your django app using gunicorn instead of django_gunicorn:
$ gunicorn mydjangoproject.wsgi:application
There is also an alternative solution to fix the gunicorn_django script, see here. I ran into the issue when upgrading from gunicorn 18.0 to 19.1.1. Cheers!