Error from Python job scheduling module each time I stop server - python

My models.py file in my Django project contains the code based on the following tutorial:
import schedule
import time
def job():
print("I'm working...")
schedule.every(3).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
Each time I run the application, I get the following output:
"C:\Program Files (x86)\JetBrains\PyCharm 2016.1\bin\runnerw.exe" C:\Python27\python.exe D:/blogpodapi/manage.py runserver 8000
I'm working...
I'm working...
It works as expected, but whenever I close the application, I get the following output:
Traceback (most recent call last):
File "D:/blogpodapi/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "D:\blogpodapi\blogpodapi\__init__.py", line 13, in <module>
time.sleep(1)
KeyboardInterrupt
Process finished with exit code 1
Further to this, my server does not start... as when I remove the abovementioned code, I get the following output:
"C:\Program Files (x86)\JetBrains\PyCharm 2016.1\bin\runnerw.exe" C:\Python27\python.exe D:/blogpodapi/manage.py runserver 8000
Performing system checks...
System check identified no issues (0 silenced).
August 14, 2016 - 14:00:32
Django version 1.9.6, using settings 'blogpodapi.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
I am not to sure what is causing this error. The server won't start when the scheduler is in place and there is an error each time I try to stop the server when it is in place. Ideally I would like the server to start as expected, and the scheduled tasks to start running after this. Any recommendations on how I can fix this?
The entirety of the models.py file can be found here: http://pastebin.com/0DwQWqM8.

There does not seem to be any problem.
The Traceback you posted reports a KeyboardInterrupt which is commonly used to force-quit an application and thus completely normal.
The server also seems to have started.
Have you tried visiting http://127.0.0.1:8000/ while the server is running?
The last line just tells you to use CTRL-C in the command line if you want to stop the server.

Related

How to overwrite Django app to Pythonanywhere?

After the second time deploying the Django app to Pythonanywhere, (I re-edited and overwritten in VS code and did git push) I got the following error.
WARNING: Package(s) not found: django
Traceback (most recent call last):
File "/home/hogehohe/.local/bin/pa_autoconfigure_django.py", line 47, in <module>
main(arguments['<git-repo-url>'], arguments['--domain'], arguments['--python'], nuke=arguments.get('--nuke'))
File "/home/hogehohe/.local/bin/pa_autoconfigure_django.py", line 36, in main
project.update_settings_file()
File "/home/hogehohe/.local/lib/python3.6/site-packages/pythonanywhere/django_project.py", line 74, in update_settings_file
new_django = version.parse(self.virtualenv.get_version("django")) >= version.parse("3.1")
File "/home/hogehohe/.local/lib/python3.6/site-packages/pythonanywhere/virtualenvs.py", line 32, in get_version
output = subprocess.check_output(commands).decode()
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/home/hogehohe/.virtualenvs/hogehohe.pythonanywhere.com/bin/pip', 'show', 'django']' returned non-zero exit status 1.
The command is
$ pa_autoconfigure_django.py https://github.com/[user_name]/[project_name].git --nuke
The first deployment succeeded but the second one is not. I don't know the cause and how to overwrite it...
You need to have a requirements.txt file in your project that specifies the packages that you need for your app. I'm guessing that your first project had one that included django and that your second one does not.

Apache Airflow Webserver error says SSL key file does not exist, even though there is one there

I am very new to SSL, certificates, and keys, so I appreciate any help and recognize I'm probably making a boneheaded mistake.
I'm running a Docker Swarm on three internal CentOS 7 servers. The Swarm deploys, in part, a custom Docker image for running Apache Airflow 1.10.0 (planning to upgrade to 1.10.1 soon). The image starts FROM python:3.5-slim, which is based on Ubuntu.
I followed this guide to generate a self-signed CA, certs, and keys. I think this is appropriate for my use case because the servers are on an internal network and the Airflow webserver will only be accessed by members of my team while they're on site or using a VPN.
Part of the docker-compose.yml is as follows in order to give the containers access to the cert and key:
version: 3.5
services:
[...]
webserver:
[...]
volumes:
- type: bind
source: /root/ca/intermediate/certs
target: /usr/local/airflow/intermediate/certs
- type: bind
source: /root/ca/intermediate/private
target: /usr/local/airflow/intermediate/private
I changed the owner of the files from within the containers to the airflow user in the container, so that the application can read them.
The relevant airflow.cfg is as follows:
[webserver]
base_url = http://localhost:443
web_server_host = 0.0.0.0
web_server_port = 443
web_server_ssl_cert = /usr/local/airflow/intermediate/certs/my_server.cert.pem
web_server_ssl_key = /usr/local/airflow/intermediate/private/my_server.key.pem
The .cert.pem and .key.pem files are the same on all three servers. I did this because I suspect the Docker Swarm routing mesh will expect uniformity across the servers. (Is this a vulnerability or otherwise a mistake?)
The Dockerfile also EXPOSEs port 443.
However, this is the error I get whenever the webserver attempts to start:
Traceback (most recent call last):
[2018-11-29 19:43:10 +0000] [36] [INFO] Starting gunicorn 19.9.0
File "/usr/local/bin/gunicorn", line 11, in <module>
sys.exit(run())
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/local/bin/gunicorn", line 11, in <module>
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 223, in run
sys.exit(run())
super(Application, self).run()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 199, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
self.start()
File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 157, in start
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 223, in run
self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
File "/usr/local/lib/python3.5/site-packages/gunicorn/sock.py", line 162, in create_sockets
super(Application, self).run()
raise ValueError('keyfile "%s" does not exist' % conf.keyfile)
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
ValueError: keyfile "/usr/local/airflow/intermediate/private/my_server.key.pem" does not exist
File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 199, in run
self.start()
File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 157, in start
self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
File "/usr/local/lib/python3.5/site-packages/gunicorn/sock.py", line 162, in create_sockets
raise ValueError('keyfile "%s" does not exist' % conf.keyfile)
ValueError: keyfile "/usr/local/airflow/intermediate/private/my_server.key.pem" does not exist
So my question is, how do I get Airflow to recognize the SSL key and certificate in an appropriate way? The Airflow documentation on the subject is pretty terse.
I hope I've provided enough context -- happy to offer more if that helps. Thanks again.

error while linking mysql and django

i am using aptana for creating a website using django. I have installed mysql but not able to link the database when i run this command *Python2.7 manage.py runserver* i get a message that Python2.7 not recognized and when i run this command Python manage.py runserver
i get a error message
C:\Users\George\Documents\Aptana Studio 3 Workspace\Firstwebsite>python manage.py runserver
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <dja
ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x028E5C
70>>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line
92, in inner_runself.validate(display_num_errors=True)
`File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in
validate num_errors = get_validation_errors(s, app)`
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 28, in
get_validation_errors from django.db import models, connection
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in
import_module__import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 17, in
<module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" %
e)django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module
named MySQLdb
I am using Django 1.5 and python 2.7 and aptana 3
I am confused whether i am tying this commands in the correct directory.
any help !!!
Did you install MySQLdb? which is a system library. A quick search on google shows a couple sites you can download this from
One of which is (link pulled from here), another post that addresses this:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
http://sourceforge.net/projects/mysql-python/files/mysql-python/
We would need to see your settings.py file to do more in depth review.
On the surface, it seems like you have not linked it to a database in the settings file. Here is a link that will help you get it installed:
http://decoding.wordpress.com/2012/01/23/how-to-setup-django-and-mysql-python-on-mac-os-x-lion/
(At least on a MAC/Unix. Windows is a different story)
After that, I would just follow any guide on linking the two.
(Some Generic one from a blog)
http://nisthaonweb.com/blog/2012/02/setting-up-django-with-mysql-with-and-without-mamp/

Django Book Ch. 3: "No Module named mysite.wsgi"

I've been stuck on this problem for what seems like forever, and none of the other threads I've found seem to help.
When I run python manage.py runserver in cmd, I get this output:
C:\Documents and Settings\ltiokhin\My Documents\DJCode\mysite>python manage.py runserver
Validating models...
0 errors found
Django version 1.4.3, using settings 'settings'
Development server is running at http:___________________________
Quit the server with CTRL-BREAK.
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x010689 F0>>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.
py", line 109, in inner_run
handler = self.get_handler(*args, **options)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 24, in get_handler
handler = super(Command, self).get_handler(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 39, in get_handler
return get_internal_wsgi_application()
File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 58, in get_internal_wsgi_application
"could not import module '%s': %s" % (app_path, module_name, e)) django.core.exceptions.ImproperlyConfigured: WSGI application 'mysite.wsgi.appli cation' could not be loaded; could not import module 'mysite.wsgi': No module na med mysite.wsgi
Thanks in advance for the help.
Do you use the same version as in the book?
Last time I had this kind of error it was because of that!
Or did you add wsgi to the installed_apps in settings.py?
Look for "wsgi.py" under the folder "C:\Documents and Settings\ltiokhin\My Documents\DJCode\mysite\mysite". Its possible that the standard django application file is missing or its named as something else.

Google App Engine - Deploy fails with Exception: Version not ready - Any Ideas?

This issue occurs when deploying either by the Google App Engine Launcher and via the command-line using appcfg.py
I have tried:
- Changing version - (doesn't work)
- Deleting version from when the issue stated (24 hours ago- around the time there was some Python issues on Google) - Doesn't work
- Install one of my other applications (works)
I have been banging my head against the wall on this for 24 hours and can't get any updates onto production
-------- Output -------------------------
Scanning files on local disk.
Cloning 10 static files.
Cloning 98 application files.
Compilation starting.
Compilation completed.
Starting deployment.
Checking if deployment succeeded.
Will check again in 1 seconds.
............
Will check again in 60 seconds.
Checking if deployment succeeded.
Will check again in 60 seconds.
Checking if deployment succeeded.
Will check again in 60 seconds.
Checking if deployment succeeded.
2012-02-24 07:38:36,362 WARNING appcfg.py:1948 Version still not ready to serve, aborting.
2012-02-24 07:38:36,363 ERROR appcfg.py:2178 An unexpected error occurred. Aborting.
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 2164, in DoUpload
app_summary = self.Commit()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 1949, in Commit
raise Exception('Version not ready.')
Exception: Version not ready.
Rolling back the update.
Password for XXXXX#XXXXXX: Traceback (most recent call last):
File "google_appengine/appcfg.py", line 101, in <module>
run_file(__file__, globals())
File "google_appengine/appcfg.py", line 97, in run_file
execfile(script_path, globals_)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 3935, in <module>
main(sys.argv)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 3926, in main
result = AppCfgApp(argv).Run()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 2497, in Run
self.action(self)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 3692, in __call__
return method()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 2915, in Update
self.UpdateVersion(rpcserver, self.basepath, appyaml)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 2904, in UpdateVersion
self.options.max_size)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 2164, in DoUpload
app_summary = self.Commit()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/appcfg.py", line 1949, in Commit
raise Exception('Version not ready.')
Exception: Version not ready.
If deploy fails you might need to 'rollback' manually.
The "Make Symlinks..." menu option can help with command-line work.
*** appcfg.py has finished with exit code 1 ***

Categories