Werkzeug server is shutting down in Django application - python

after updating the Werkzeug version from 2.0.3 to 2.1.0, I keep getting errors every time I run the server, and here is the error log:
Exception happened during processing of request from ('127.0.0.1', 44612)
Traceback (most recent call last):
File "/usr/lib/python3.8/socketserver.py", line 683, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.8/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.8/socketserver.py", line 747, in __init__
self.handle()
File "/home/oladhari/.virtualenvs/reachat/lib/python3.8/site-packages/werkzeug/serving.py", line 363, in handle
super().handle()
File "/usr/lib/python3.8/http/server.py", line 427, in handle
self.handle_one_request()
File "/usr/lib/python3.8/http/server.py", line 415, in handle_one_request
method()
File "/home/oladhari/.virtualenvs/reachat/lib/python3.8/site-packages/werkzeug/serving.py", line 243, in run_wsgi
self.environ = environ = self.make_environ()
File "/home/oladhari/.virtualenvs/reachat/lib/python3.8/site-packages/django_extensions/management/commands/runserver_plus.py", line 326, in make_environ
del environ['werkzeug.server.shutdown']
KeyError: 'werkzeug.server.shutdown'
this exception keep appearing while incrementing by 2 ( ('127.0.0.1', 44612) -> ('127.0.0.1', 44628) and the server crash
checking the changes log, I have found this detail:
Remove previously deprecated code. #2276
Remove the non-standard shutdown function from the WSGI environ when running the development server. See the docs for alternatives.
here is the link to the changes log
it asks to check the documentation for alternatives but can not find any
please let me know how I would resolve this error, thank you
NB: my python version is 3.8

Literally just ran into this today. According to their (git repo issue 1715) and assuming you are running runserver_plus, there are three options that worked for some users. The first worked for me:
Not altering your files and adding the option --keep-meta-shutdown. My full command looks like python manage.py runserver_plus --cert-file /path/to/cert.pem --key-file /path/to/key.pem --keep-meta-shutdown localhost:9000
Comment out open lines 325 and 326 under your runserver_plus.py
Upgrading python to 3.10
Hope this helps!

The Django-extensions issue for this recommends running runserver_plus with the --keep-meta-shutdown argument.
Alternatively, you can just downgrade Werkzeug to 2.0.* until this is fixed:
pip install Werkzeug==2.0.*
If using a requirements.txt file, use the following:
Werkzeug==2.0.*

Related

Site-packages error in CKAN connected to ckanext-showcase

I have installed a CKAN Instance and I have installed the ckanext-showcase module.
Although the installation didn't raise any errors and I was able to add a few showcases when some of my users that I had set as showcase administrators started adding showcases the module has stopped working.
The page {portal.url/showcase} can't be viewed unless I am connected as system administrator. When a user or even a showcase user tries to enter the page get's an internal server error.
From that point on when I am trying to create a new system administrator from console with the paster command (http://docs.ckan.org/en/latest/maintaining/getting-started.html#create-admin-user) I get the bellow message
Traceback (most recent call last):
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 703, in
main()
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 683, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 282, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 204, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 173, in addpackage
exec(line)
File "", line 1, in
KeyError: 'ckanext'
Because I don't have the ability to install the CKAN again right now, is there any suggestions on how I to fix this?
Any help would be greatly appreciated
After looking to my server error logs I found that the error wasn't caused by the plugin ckanext-showcase but from the module ckanext-datarequests.
The first part of my problem was connected to a server error coming at a 401 Unauthorized exception not being handled at version 1.0.2 of the plugin. As soon as I upgraded to the latest version 1.0.3 the error was fixed.

Failure during project creation using 'djangocms' command

Django CMS 3.4.1
Django 1.10.2
pip modules: http://pastebin.com/vJWvZVfA
pip 8.1.2
Python 2.7.12
OS: Amazon Linux AMI release 2016.03
I'm new to Django CMS, Django, and Python. My previous CMS experience has been with WordPress and I'm try to try out Django CMS as an alternative to WordPress, but am getting an error that I can not seem to figure out. I have updated the pip modules and installed others as suggested in threads on StackOverflow, but to no avail.
I followed the tutorial the instructions, with the exception of the djangocms command, which is incorrect in the tutorial. (It's missing the -w flag.)
EDIT: As requested, here is the output with the --verbose flag added:
(env)[ec2-user#(redacted) tutorial-project]$ djangocms -d postgres://(redacted) -e no --permissions yes -l "en-CA, en-US, en, fr-CA, fr-FR" -p . --starting-page yes --verbose --utc mysite
Creating the project
Please wait while I install dependencies
Package install command: install django-cms<3.5 djangocms-admin-style>=1.2,<1.3 django-treebeard>=4.0,<5.0 psycopg2 djangocms-text-ckeditor>=3.2.1 djangocms-link>=1.8 djangocms-style>=1.7 djangocms-googlemap>=0.5 djangocms-snippet>=1.9 djangocms-video>=2.0 djangocms-column>=1.6 easy_thumbnails django-filer>=1.2 cmsplugin-filer>=1.1 Django<1.9 pytz django-classy-tags>=0.7 html5lib>=0.999999,<0.99999999 Pillow>=3.0 django-sekizai>=0.9 django-select2<5.0six
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-duWZSN/psycopg2/
The installation has failed.
*****************************************************************
Check documentation at https://djangocms-installer.readthedocs.io
*****************************************************************
Traceback (most recent call last):
File "/home/ec2-user/env/bin/djangocms", line 11, in <module>
sys.exit(execute())
File "/home/ec2-user/env/local/lib/python2.7/site-packages/djangocms_installer/main.py", line 33, in execute
verbose=config_data.verbose
File "/home/ec2-user/env/local/lib/python2.7/site-packages/djangocms_installer/install/__init__.py", line 91, in requirements
output = subprocess.check_output(['pip'] + args)
File "/usr/lib64/python2.7/subprocess.py", line 574, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '[u'pip', u'install', u'django-cms<3.5', u'djangocms-admin-style>=1.2,<1.3', u'django-treebeard>=4.0,<5.0', u'psycopg2', u'djangocms-text-ckeditor>=3.2.1', u'djangocms-link>=1.8', u'djangocms-style>=1.7', u'djangocms-googlemap>=0.5', u'djangocms-snippet>=1.9', u'djangocms-video>=2.0', u'djangocms-column>=1.6', u'easy_thumbnails', u'django-filer>=1.2', u'cmsplugin-filer>=1.1', u'Django<1.9', u'pytz', u'django-classy-tags>=0.7', u'html5lib>=0.999999,<0.99999999', u'Pillow>=3.0', u'django-sekizai>=0.9', u'django-select2<5.0six']' returned non-zero exit status 1
EDIT 2: (moved to answer)
EDIT 3:
After solving the first part, another error remains. I'll include it in this post since it still falls under the topic of the title:
Creating the project
Project creation command: /home/ec2-user/env/bin/python2.7 /home/ec2-user/env/bin/django-admin.py startproject mysite /home/ec2-user/tutorial-project
Database setup commands: /home/ec2-user/env/bin/python2.7 -W ignore manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 191, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 118, in connect
conn_params = self.get_connection_params()
File "/home/ec2-user/env/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 158, in get_connection_params
"settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value.
The installation has failed.
*****************************************************************
Check documentation at https://djangocms-installer.readthedocs.io
*****************************************************************
Traceback (most recent call last):
File "/home/ec2-user/env/bin/djangocms", line 11, in <module>
sys.exit(execute())
File "/home/ec2-user/env/local/lib/python2.7/site-packages/djangocms_installer/main.py", line 41, in execute
django.setup_database(config_data)
File "/home/ec2-user/env/local/lib/python2.7/site-packages/djangocms_installer/django/__init__.py", line 388, in setup_database
output = subprocess.check_output(command, env=env)
File "/usr/lib64/python2.7/subprocess.py", line 574, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/home/ec2-user/env/bin/python2.7', u'-W', u'ignore', u'manage.py', u'migrate']' returned non-zero exit status 1
I'm going to guess that the problem lies in the message:
settings.DATABASES is improperly configured. Please supply the NAME value.
The installation has failed.
I'm using PostgreSQL, so I assume that the error is caused by the schema not being provided in the command argument. There was nothing in the guide that I saw indicating how to provide it, so I'll have to search some more.
The error message tells me absolutely nothing. It only tells me that Django tried to use pip to install something and for whatever reason it failed. In order to figure out what went wrong, try enabling verbose mode (python -v). If that gives the same output, or that isn't an option because you're using a program that calls Python (which it sounds like you are), let me know and prepare to go into the source code. Trust me, I have taken many a dive into source code for Python utilities, and as long as you don't do anything stupid (like delete a file) it's pretty hard to mess anything up. Even if you do you can always reinstall Django (or make a backup first). Don't worry about messing up your computer. You'd have to work hard to make Django do that!
Original error
The non-verbose error message indicates the error in a cryptic way, and using --verbose provides a more understandable message.
I was missing one required module (psycopg2) and four others were versions which were too new (easy_thumbnails, Django, html5lib, django-select2).
I uninstalled the four modules and then reinstalled them using the version requirement in the command. e.g. pip install 'Django<1.10'.
psycopg2 required extra steps, as I got an error message when trying to install it indicating that it could not find pg_config. Another SO answer advised that I just had to install postgresql-devel. After I did that, (sudo yum install postgresql-devel), I also uninstalled postgresql8-libs, as postgresql-devel came with a newer version. I didn't do it before since yum indicated a PHP dependency, and I wasn't sure if it would cause problems if I did.
Second error
Pretty simple. I was missing the /NAME component of the database URL (postgres://USER:PASSWORD#HOST:PORT/NAME).

MPLD3 not showing graph in browser

I'm using Google Chrome on Mac OS X 10.11.4. Im trying to run this example from the mpld3 library. I read that mpld3 does not work on python 3.5,
The mpld3 project is compatible with Python 2.6-2.7 and 3.3-3.4.
so I created a 3.4 environment using:
conda create -n py34 python=3.4 anaconda
When running the script I get the following error:
Exception happened during processing of request from ('127.0.0.1', 52484)
Traceback (most recent call last):
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/socketserver.py", line 305, in _handle_request_noblock
self.process_request(request, client_address)
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/socketserver.py", line 331, in process_request
self.finish_request(request, client_address)
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/socketserver.py", line 673, in __init__
self.handle()
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/http/server.py", line 401, in handle
self.handle_one_request()
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/http/server.py", line 389, in handle_one_request
method()
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/site-packages/mpld3/_server.py", line 38, in do_GET
self.wfile.write("<html><head>"
File "/Users/Neill/anaconda/envs/py34/lib/python3.4/socket.py", line 398, in write
return self._sock.send(b)
TypeError: 'str' does not support the buffer interface
I also made sure that the latest version of mpld3 is installed. The local server then displays a blank page. Chrome's developer tools also report no errors. Does anyone have an idea what the problem might be?

Python socket server errors upon PyCharm arcpy import - what have I not set up?

I am having trouble with setting up my development environment (the latest release Community build of PyCharm). I have been using the previous version to write python scripts for ArcGIS processing. To do this you need to import the ArcGIS python API - arcpy. This has always been fine but now I can't seem to access arcpy directly.
I have the ArcGIS location added to my python path, to my project settings paths and can instantiate an instance of an arcpy object but trying to interact with top level methods or classes generates a socket server error (below). For example from the interactive prompt:
>> import arcpy - will work
but typing
>> arcpy. - will instantly generate
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.3\lib\SocketServer.py", line 295, in _handle_request_noblock
Exception happened during processing of request from ('127.0.0.1', 59487)
self.process_request(request, client_address)
File "C:\Python27\ArcGIS10.3\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\ArcGIS10.3\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\ArcGIS10.3\lib\SocketServer.py", line 653, in __init__
self.finish()
File "C:\Python27\ArcGIS10.3\lib\SocketServer.py", line 712, in finish
self.wfile.close()
File "C:\Python27\ArcGIS10.3\lib\socket.py", line 279, in close
self.flush()
File "C:\Python27\ArcGIS10.3\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
However - if I ignore this and instantiate and instance of a map document for example
>>import arcpy
>>fullpath = r'C:\Temp\some.mxd' # where this is a valid ESRI map doc
>> my_mapdoc_object = arcpy.mapping.MapDocument(fullpath)
I can now interact with the object.
What am I doing wrong with setting up my environment?
Appears to be a docstring issue that PyCharm is tripping over.
Within arcpy, within the docstring of one of the tool functions, there is an escape character, specifically \a, in a data path. If that is corrected, the error goes away.

Connection to AWS timed out using Python boto

I ran Python program in Cygwin to connect to AWS, but failed consistently as being timed out. But my connection to AWS using aws cli in Cygwin always works. Also if I run the same python code in Windows, it also works. I have checked all the connection credentials which are the same for all.
Here is the error msg:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 585, in get_all_instances
max_results=max_results)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/ec2/connection.py", line 681, in get_all_reservations
[('item', Reservation)], verb='POST')
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1170, in get_list
response = self.make_request(action, params, path, verb)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1116, in make_request
return self._mexe(http_request)
File "/usr/lib/python2.7/site-packages/boto-2.38.0-py2.7.egg/boto/connection.py", line 1030, in _mexe
raise ex
socket.error: [Errno 116] Connection timed out
I have found out that the culprit lies in the proxy credentials.
I put HTTP_PROXY and HTTPS_PROXY as Windows Environment Variables. However, when run in Cygwin, boto uses 'http_proxy' to match without considering the case of the word
(see /boto/connection.py(669)handle_proxy()
line 669: if 'http_proxy' in os.environ and not self.proxy:).
When I changed the capital case HTTP_PROXY to lower case http_proxy, then it worked. Not sure why it isn't a problem if I run with Python in Windows.

Categories

Resources