AttributeError: module 'signal' has no attribute 'SIGHUP' - django

I am trying to integrate mod_wsgi into my django project on Windows 10. While I was able to install mod_wsgi into my virtual environment, I am running into errors while trying the command python manage.py runmodwsgi.
(venv) PS D:\Tutorials\Python\Projects\ADSS> python manage.py runmodwsgi
Successfully ran command.
Server URL : http://localhost:8000/
Server Root : C:/Users/admin/AppData/Local/Temp/mod_wsgi-localhost-8000-admin
Server Conf : C:/Users/admin/AppData/Local/Temp/mod_wsgi-localhost-8000-admin/httpd.conf
Error Log File : C:/Users/admin/AppData/Local/Temp/mod_wsgi-localhost-8000-admin/error_log (warn)
Operating Mode : daemon
Request Capacity : 5 (1 process * 5 threads)
Request Timeout : 60 (seconds)
Startup Timeout : 15 (seconds)
Queue Backlog : 100 (connections)
Queue Timeout : 45 (seconds)
Server Capacity : 20 (event/worker), 20 (prefork)
Server Backlog : 500 (connections)
Locale Setting : en_US.cp1252
Traceback (most recent call last):
File "D:\Tutorials\Python\Projects\ADSS\manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\base.py", line 448, in execute
output = self.handle(*args, **options)
File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\mod_wsgi\server\management\commands\runmodwsgi.py", line 162, in handle
signal.signal(signal.SIGHUP, handler)
AttributeError: module 'signal' has no attribute 'SIGHUP'
Google seems to suggest that signal.SIGHUP, signal.SIGUSR1 and signal.SIGWINCH as being used by my mod_wsgi installation aren't supported on Windows. So I tried the following two methods in .\venv\Lib\site-packages\mod_wsgi\server\management\commands\runmodwsgi.py:
I tried using the if-condition if platform.system() != 'Linux': as suggested on this Q&A,
I also tried commenting out the lines making use of these signals in this file.
In either case, I kept running across some or the other error, making me wonder if my installation of mod_wsgi is correct at all.
I have been following the instructions as written on mod_wsgi's PyPi listing. I am writing them here for reference:
Obtained a copy of Apache 2.4.54 Win64 from https://www.apachelounge.com/download/
Extracted this zip file and placed the Apache24 folder in my C: as C:\Apache24.
Set Define SRVROOT "c:/Apache24" and Listen 8000 in httpd.conf. Verified that things work and the default homepage is loaded (http://localhost:8000).
Installed Visual Studio C++ build tools using Visual Studio Installer (the 'Desktop development with C++' category).
Installed mod_wsgi into my virtual environment by running the command pip install mod-wsgi in my active virtual environment in an x64 Native Tools Command Prompt for VC2022 window.
Added 'mod_wsgi.server', to the list of INSTALLED_APPS in my settings.py.
Ran python manage.py collectstatic
Ran mod_wsgi-express module-config which output the following three lines, which I placed at the end of my httpd.conf:
LoadFile "C:/Program Files/Python310/python310.dll"
LoadModule wsgi_module "D:/Tutorials/Python/Projects/ADSS/venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "D:/Tutorials/Python/Projects/ADSS/venv"
Ran python manage.py runmodwsgi, which is resulting in the error log I mentioned at the start of my post.
Please throw light on what I might be doing incorrectly.
I also have Visual Studio installed, which I am using for this project.
I changed from port 80 to port 8000 in httpd.conf because my IIS doesn't allow Apache to run on port 80.

Okay. So I found a workaround which works.
Instead of relying on mod_wsgi's buil-in admin script which is triggered by the command python manage.py runmodwsgi, I followed Johnnyboycurtis's method as explained in his video here.
Johnnyboycurtis's method of django application deployment on Apache in Windows environment worked right out of the box. However, apache wasn't serving static files, even though I followed the instructions as per the django documentation here.
So, to serve the static files, I installed WhiteNoise. Now, things seem to be working fine.

Related

Sending a lockfile to django-post_office send_queued_mail

This doesn't seem like it should be hard, but I'm stumped. I've gotten django-post_office integrated with my codebase, and now I'm trying to test that I can set up cron jobs for queued email as described in the docs:
https://github.com/ui/django-post_office
Whether I run on the command line or in crontab, I get the same problem:
python manage.py send_queued_mail lockfile='/home/gbeadmin/tmp/post_office.lock'
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/gbeadmin/webapps/gbe2016test/lib/python2.7/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/gbeadmin/.local/lib/python2.7/site-packages/post_office/management/commands/send_queued_mail.py", line 33, in handle
options['lockfile'])
KeyError: 'lockfile'
Digging around, I see that I should be able to specify the lockfile, so I've tried:
python manage.py send_queued_mail --lockfile='<path to lock file>'
Which then gives me the error:
Usage: manage.py send_queued_mail [options]
manage.py: error: no such option: --lockfile
I've also tried the '-L' option listed in the docs, with the same basic result.
I'm lost - I don't see a bug in my syntax, I don't see any other way to set the lock file...
Other notes:
I'm running in WebFactional
I'm running django 1.6 (yes, I want to upgrade, that is on the way but can't be in the scope for this ticket)
django-post_office - 2.0.8
python 2.7
I'm sorry to hear your problem, but the problem is located in the management command. You see, the KeyError means the 'lockfile' does not exist in the dictionary. Further investigation yields that the root cause of the problem is in the management command. The management command syntax is valid only for Django 1.8 and up. They're currently dropping support for Django < 1.8. Hope this helps !
I had the same issue using django-post-office. Downgrading to versions (1.1.2, 1.1.0, 1.0.0) also didn't help.
FYI, I was using Python 2.7.7 and Django version (1, 4, 2, 'final', 0)
I tried django-mailer instead. Link Here and it worked like a charm. Followed the same steps used with django-post-office.
pip install django-mailer
Added the following to my settings.py file
INSTALLED_APPS = [
...
"mailer",
...
]
EMAIL_BACKEND = "mailer.backend.DbBackend"
After, I ran this command
python manage.py syncdb
It created the following tables:
Creating table mailer_message
Creating table mailer_dontsendentry
Creating table mailer_messagelog
No change is further required in your code.
After i sent some mails in my application, they were added to the db table mailer_message
To send those emails, i used the management command added by django-mailer
python manage.py send_mail
After the messages were sent, they were removed from the db table and added to the logs table - mailer_messagelog instead. You could create a cron job to run this command after a given interval of time.
Hope this helps.

django makemigrations with python-social-auth leads to permission denied error

After adding python social auth to my installed apps, i.e.
INSTALLED_APPS = (
...
'social.apps.django_app.default',
...
)
and then trying a
python manage.py makemigrations
I get an unsurprising permissions error
Migrations for 'default':
0002_auto_20150217_2053.py:
- Alter field user on usersocialauth
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management /__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 124, in handle
self.write_migration_files(changes)
File "/usr/lib/python2.7/site-packages/django/core/management/commands /makemigrations.py", line 153, in write_migration_files
with open(writer.path, "wb") as fh:
IOError: [Errno 13] Permission denied: u'/usr/lib/python2.7/site-packages/social/apps/django_app/default/migrations/0002_auto_20150217_2053.py'
It makes sense that I can not write to system wide package installation directories.
There are some obvious ways around this, like changing the permissions on the site-packages/social directories. However, is this the only way of doing this, or am I missing something?
With the accepted solution above, you're effectively putting project files in your python environment. And every time you deploy to a new server, you'd have to run makemigrations to create those file(s).
How about telling makemigrations to put the social migrations inside your own project?
MIGRATION_MODULES = {
# social.apps.django_app.default
'default': 'myproject.mysocial.migrations',
}
That way, when you deploy to your server, your project is self-contained and will work without hacking your Python environment.
As stated in your question, changing the permissions on the directories would be a solution. Yet, another way to do this is to create an isolated Python environment for your Django project using virtualenv. Or, more conveniently, the extension virtualenvwrapper.
Install the later like this:
$ pip install virtualenvwrapper
The following creates an activates a virtualenv for your project:
$ mkvirtualenv django_project
$ workon django_project
After that, you are free to install Django and Python Social Auth
$ pip install django
$ pip install python-social-auth
You will notice that all this will be installed in $HOME/.virtualenvs/django_project
This is a common, recommended practice among Python and Django users. It will solve the permission issues, as well as other dependency issues that you may run into if you use your system's Python installation for all your projects.
Note that Python Social Auth does in fact require the creation of a migration before its use in a Django project, the migration adds a related_name to the foreign key 'user' in the 'UserSocialAuth' model
None of these answers addresses your issue, as far as I can tell. Simply installing a new application shouldn't require creation of new migration files; they should, one would expect, be shipped with the application package.
This looks like a bug or an oversight by the package author.

CKAN install on Ubuntu (cannot create std instance)

I'm trying to install CKAN 1.8 on a virtual machine with Ubuntu 10.04.
The installation ended well, but when I create the std instance, appears an error in Python that I can not solve.
Can anyone help me with this?
Transcription of the messages in the terminal:
egov#egov-VirtualBox:~$ sudo ckan-create-instance std default.vm.buildkit yes
Installing or upgrading CKAN std ...
Ensuring users and groups are set up correctly ...
Ensuring directories exist for std CKAN INSTANCE ...
Disabling the crontab for the ckanstd user ...
Putting CKAN into maintenance mode ...
Site std disabled.
To activate the new configuration, you need to run:
service apache2 reload
Enabling site std.maint.
To activate the new configuration, you need to run:
service apache2 reload
* Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
Setting log file permissions so that both Apache and cron jobs can log to the same place ...
Ensuring who.ini file exists ...
Ensuring wsgi.py file exists ...
Making sure PostgreSQL is running ...
Setting the password of the std user in PostgreSQL
Setting the std user password ...
ALTER ROLE
Ensuring the std database exists ...
Overwriting the existing Apache config ...
Performing any database upgrades ...
Traceback (most recent call last):
File "/usr/bin/paster", line 4, in <module>
command.run()
File "/usr/lib/python2.7/dist-packages/paste/script/command.py", line 104, in run
invoke(command, command_name, options, args[1:])
File "/usr/lib/python2.7/dist-packages/paste/script/command.py", line 143, in invoke
exit_code = runner.run(args)
File "/usr/lib/python2.7/dist-packages/paste/script/command.py", line 238, in run
result = self.command()
File "/usr/lib/pymodules/python2.7/ckan/lib/cli.py", line 120, in command
self._load_config()
File "/usr/lib/pymodules/python2.7/ckan/lib/cli.py", line 82, in _load_config
load_environment(conf.global_conf, conf.local_conf)
File "/usr/lib/pymodules/python2.7/ckan/config/environment.py", line 141, in load_environment
p.load('synchronous_search')
File "/usr/lib/pymodules/python2.7/ckan/plugins/core.py", line 122, in load
service = _get_service(plugin)
File "/usr/lib/pymodules/python2.7/ckan/plugins/core.py", line 77, in _get_service
return plugin.load()(name=name)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1989, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/pymodules/python2.7/ckan/lib/search/__init__.py", line 2, in <module>
from pylons import config, c
ImportError: cannot import name c
Bringing the std INSTANCE out of maintenance mode ...
Site std.maint disabled.
To activate the new configuration, you need to run:
service apache2 reload
Enabling site std.
To activate the new configuration, you need to run:
service apache2 reload
* Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
Reloading apache ...
* Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
Enabling crontab for the ckanstd user ...
The issue is at the end of the stack trace:
File "/usr/lib/pymodules/python2.7/ckan/lib/search/__init__.py", line 2, in <module>
from pylons import config, c
ImportError: cannot import name c
This suggests pylons (a required library) may not install correctly. You could check this by doing:
$ python
>>> import pylons
If that fails then something has gone wrong in the install and pylons is not installed (as it should be).
At that point it would be worth trying a reinstall.
Please let me know if this helps (or not) and will try to assist further.

Python exceptions in core files while using Jython, Weblogic, modjy

This is the first time I'm trying to run a Django app on top of Jython, using Weblogic and modjy.
I've installed locally Jython 2.5.3, and I'm able to run my Django application using the dev server (jython manage.py runserver) without glitches.
I'm on OSX 10.7.4 and these are my Java info:
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
Then I tried to deploy the app in WebLogic. I've used the django-jython package to generate the WAR file. When I try to deploy it using the WebLogic web console, I get the following exception when it tries to startup the app:
Servlet: "modjy" failed to preload on startup in Web application: "bbb". Traceback (innermost last): File "/Users/fabio/weblogic/novartis/servers/myserver/stage/bbb/bbb/WEB-INF/lib-python/Lib/site.py", line 421, in ? File "/Users/fabio/weblogic/novartis/servers/myserver/stage/bbb/bbb/WEB-INF/lib-python/Lib/site.py", line 402, in main File "/Users/fabio/weblogic/novartis/servers/myserver/stage/bbb/bbb/WEB-INF/lib-python/Lib/site.py", line 92, in removeduppaths NameError: set :org.python.core.PyException:null
This is the expanded WAR file I'm trying to deploy: http://www.2shared.com/file/aec-0BR8/bbb.html
So the weird error seems to be inside a core python module (site.py). I went inside this file, expanding the WAR file, and I "fixed" it (just to see what happened next) by doing
from sets import Set as set
at line 92 in WEB-INF/lib-python/Lib/site.py
This lead to another error:
[HTTP:101216]Servlet: "modjy" failed to preload on startup in Web application: "bbb". Traceback (innermost last): File "/Users/fabio/weblogic/novartis/servers/myserver/stage/bbb/bbb/WEB-INF/lib-python/Lib/site.py", line 422, in ? File "/Users/fabio/weblogic/novartis/servers/myserver/stage/bbb/bbb/WEB-INF/lib-python/Lib/site.py", line 403, in main File "/Users/fabio/weblogic/novartis/servers/myserver/stage/bbb/bbb/WEB-INF/lib-python/Lib/site.py", line 98, in removeduppaths File "/Users/fabio/weblogic/novartis/servers/myserver/stage/bbb/bbb/WEB-INF/lib-python/Lib/site.py", line 68, in makepath AttributeError: class 'org.python.modules.os' has no attribute 'path' :org.python.core.PyException:null
Again, related to a core python module.
It should be noted that if I try to remove the jython.jar file inside WEB-INF/lib/jython.jar I don't get any error, while I was expecting it to be referenced when deploying the WAR file.
Thanks for any input on this.

Django Import Error using EC2 and bitnami

I am trying to deploy my django app to amazon's ec2. I ran into some trouble getting my site-packages and my middleware working on the ec2 server. i am using bitnami djangostack for my AMI but am confused where on the server to put my site-packages (like registration south etc) and where to put my middleware (like pagination).
right now i am running the server and getting the following error:
Traceback (most recent call last):
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
self.load_middleware()
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
ImproperlyConfigured: Error importing middleware pagination.middleware: "No module named pagination.middleware"
you can see the error at the following link
site-packages is not somewhere you manually add items. Let Python's installation tools - pip and easy_install do the job for you.
As for middleware, it can go anywhere that is in your PYTHONPATH. The best place to put it is in a file that is in one of your app's directory (same place you see models.py); typically this file is called middleware.py
If the middleware is part of a third-party application; first install that application. Typically this is done with sudo easy_install package-name. Use sudo to install it in the global python site-packages directory.
A better approach is to use a virtual environment.