This question already has answers here:
Running Flask from IPython raises SystemExit
(4 answers)
Why does running the Flask dev server run itself twice?
(7 answers)
Closed 1 year ago.
I'm trying to run a most simple demo of flask app in an iPython notebook like this.
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello_world():.
return 'Hello World!'
if __name__ == '__main__':
app.run(d)
The first time I run it, all is fine. Then I interrupted the cell with app.run() in it. But the next time I run it, the notebook throws back some error message like this:
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
Then I %tbed and get the following traceback:
SystemExit Traceback (most recent call last)
<ipython-input-7-a59dfe133898> in <module>()
----> 1 myapp.run(debug=True)
C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\flask\app.pyc in run(self, host, port, debug, **options)
770 options.setdefault('use_debugger', self.debug)
771 try:
--> 772 run_simple(host, port, self, **options)
773 finally:
774 # reset the first request information if the development server
C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\werkzeug\serving.pyc in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
688 from ._reloader import run_with_reloader
689 run_with_reloader(inner, extra_files, reloader_interval,
--> 690 reloader_type)
691 else:
692 inner()
C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\werkzeug\_reloader.pyc in run_with_reloader(main_func, extra_files, interval, reloader_type)
248 reloader.run()
249 else:
--> 250 sys.exit(reloader.restart_with_reloader())
251 except KeyboardInterrupt:
252 pass
SystemExit: 1
Not telling me much so I looked at the cmd where I started iPython and see this:
Traceback (most recent call last):
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\__main__.py", line 3, in <module>
app.launch_new_instance()
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\traitlets\config\application.py", line 588, in launch_instanceapp.initialize(argv)
File "<decorator-gen-122>", line 2, in initialize
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\tra
itlets\config\application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 375, in initialize
self.init_sockets()
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 231, in init_sockets
self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 173, in _bind_socket
s.bind("tcp://%s:%i" % (self.ip, port))
File "zmq/backend/cython/socket.pyx", line 489, in zmq.backend.cython.socket.S
ocket.bind (zmq\backend\cython\socket.c:4824)
File "zmq/backend/cython/checkrc.pxd", line 25, in zmq.backend.cython.checkrc.
_check_rc (zmq\backend\cython\socket.c:7055)
raise ZMQError(errno)
ZMQError: Address in use
Seems iPython notebook server didn't handle my interruption properly. But when I tried to look for the ghost process, which listens to port 5000, I got nothing. I guess a reboot may most probably fix everthing, but just wondering if there's a fix that does not require a reboot?
Set debug=False
app.run(debug=False)
Related
I am running apache-superset using docker-compose by following the instructions here (https://superset.apache.org/docs/installation/installing-superset-using-docker-compose/) using docker-compose-non-dev.yml.
I have also added sqlalchemy-dremio to superset/docker/requirements-local.txt, in order to add dremio support as mentioned here (https://superset.apache.org/docs/databases/docker-add-drivers)
For dremio, I have a seperate container running on dremio/dremio-oss image using
docker run -p 9047:9047 -p 31010:31010 -p 45678:45678 -p 32010:32010 dremio/dremio-oss
and then made an account in dremio using the web interface at localhost:9047
But when I try to add dremio as a database in superset I get the following errors
on pressing test connection I get the following error
The connection string I'm using is
dremio+flight://dremio:dremio123#host.docker.internal:32010/dremio;SSL=0
At first I thought it might be a network error or an error in dremio, but I can connect to dremio using the python script here https://github.com/dremio-hub/arrow-flight-client-examples/blob/main/python/example.py
python example.py -host host.docker.internal -query 'SELECT 1'
This script runs successfully from both outside the container from host_os using localhost and from inside the superset_app container using host.docker.internal as host. Therefore I don't think its a network configuration problem, also this confirms that the sqlalchemy-dremio package was installed properly inside the superset containers.
Here is the docker logs for this error from superset_app container
2022-09-30 16:34:09,635:WARNING:superset.views.base:SupersetErrorsException
Traceback (most recent call last):
File "/app/superset/databases/commands/test_connection.py", line 123, in run
raise DBAPIError(None, None, None)
sqlalchemy.exc.DBAPIError: (builtins.NoneType) None
(Background on this error at: https://sqlalche.me/e/14/dbapi)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.8/site-packages/flask_appbuilder/security/decorators.py", line 89, in wraps
return f(self, *args, **kwargs)
File "/app/superset/views/base_api.py", line 114, in wraps
raise ex
File "/app/superset/views/base_api.py", line 111, in wraps
duration, response = time_function(f, self, *args, **kwargs)
File "/app/superset/utils/core.py", line 1572, in time_function
response = func(*args, **kwargs)
File "/app/superset/utils/log.py", line 244, in wrapper
value = f(*args, **kwargs)
File "/app/superset/views/base_api.py", line 84, in wraps
return f(self, *args, **kwargs)
File "/app/superset/databases/api.py", line 708, in test_connection
TestConnectionDatabaseCommand(item).run()
File "/app/superset/databases/commands/test_connection.py", line 148, in run
raise DatabaseTestConnectionFailedError(errors) from ex
superset.databases.commands.exceptions.DatabaseTestConnectionFailedError: [SupersetError(message='(builtins.NoneType) None\n(Background on this error at: https://sqlalche.me/e/14/dbapi)', error_type=<SupersetErrorType.GENERIC_DB_ENGINE_ERROR: 'GENERIC_DB_ENGINE_ERROR'>, level=<ErrorLevel.ERROR: 'error'>, extra={'engine_name': 'Dremio', 'issue_codes': [{'code': 1002, 'message': 'Issue 1002 - The database returned an unexpected error.'}]})]
***************
['UID=dremio', 'PWD=dremio123', 'HOST=host.docker.internal', 'PORT=32010', 'Schema=dremio', 'SSL=0']
***************
Ensure you are installing the latest version of sqlalchemy_dremio. You may need to install from source as setup.py wasn't updated accordingly (around time of writing). You will also need to add some SQLAlchemy base functions to sqlalchemy_dremio. Have a look at the following issue: https://github.com/narendrans/sqlalchemy_dremio/issues/20
I'm sure this is my fault, but my system has been working for months and now does not work. I've looked in Django docs and here on stackoverflow, and I understand the issue that 'connection refused' means nobody is listening on the socket; but I don't understand why, and don't know how to go forward.
I use Vagrant + VirtualBox on a MacPro, and for six months I have been able to create virtual machines and run my app with no problems. I have some VM's where everything works as expected.
On my newly-created Vagrant VM's, I install and configure my django apps and run them using 'python manage.py runserver --settings=mumble.settings.py 0.0.0.0:8000'. Note that this is Django 1.8.3, but again,it works fine on some VM's.
For mysterious reasons, when I create a new vagrant VM and install my django payload (using deploy scripts that haven't changed), and connect to the django server, I get Errno 111 Connection refused:
+ python ./manage.py runserver --settings=mydjango.settings 0.0.0.0:8000
.....
_d^^^^^^^^^b_
.d'' ``b.
.p' `q.
.d' `b.
.d' `b. * Mezzanine 4.0.1
:: :: * Django 1.8.3
:: M E Z Z A N I N E :: * Python 2.7.12
:: :: * MySQL 5.7.18
`p. .q' * Linux 4.4.0-75-generic
`p. .q'
`b. .d'
`q.. ..p'
^q........p^
''''
Performing system checks...
System check identified no issues (0 silenced).
May 31, 2017 - 09:50:50
Django version 1.8.3, using settings 'mydjango.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response
'request': request
File "/usr/lib/python2.7/logging/__init__.py", line 1185, in error
Log 'msg % args' with severity 'ERROR'.
File "/usr/lib/python2.7/logging/__init__.py", line 1193, in error
self._log(ERROR, msg, args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1286, in _log
self.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1296, in handle
self.callHandlers(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
hdlr.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 759, in handle
self.emit(record)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 129, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 132, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 98, in mail_admins
mail.send(fail_silently=fail_silently)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
error: [Errno 111] Connection refused
[31/May/2017 09:50:55]"GET /donate/ HTTP/1.1" 500 59
Things I know:
'python ./manage.py' with no arguments will run fine, and shows the help message.
All forms of addressing the web server will fail:
curl http://localhost:8000
curl http://127.0.0.1:8000
curl http://192.168.33.10:8000
from a browser: http://192.168.33.10:8000
nginx is serving on port 80, no problem
my database is a copy of the production database, and it looks fine through 'mysql'
And here is a weird thing: I brought down the Django tutorial, used the 'runserver' command, and it worked!
[vagrant][~/tmp/django_tutorial/mysite]
$ python manage.py runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
May 30, 2017 - 20:36:44
Django version 1.8.3, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[30/May/2017 20:37:05]"GET / HTTP/1.1" 200 1767
Any suggestions on how to debug this?
The answer has nothing to do with my environment. My co-worker added a name to settings.ADMINS, which had been an empty list before that. When ADMINS is a non-empty list, any error triggers an attempt to send email to all of the email addresses in ADMINS, and my VM was not configured to send email. This is documented but not emphasized. The problem did not happen to my coworker, because that associated changes did not trigger a server error.
I'm wondering what is the difference when I run a python program from PyCharm or from the command line.
Actually I'm using a library called wand-py (ImageMagick binding).
If I run my program from the command line it works.
Though if I use PyCharm Run or debug it doesn't and I get the following traceback.
/Users/alexisbenoist/Documents/python/papyrus/env/bin/python "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py" --multiproc --client 127.0.0.1 --port 58993 --file /Users/alexisbenoist/Documents/python/papyrus/tets.py
Connected to pydev debugger (build 135.973)
pydev debugger: process 73166 is connecting
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py", line 1733, in <module>
debugger.run(setup['file'], None, None)
File "/Applications/PyCharm CE.app/helpers/pydev/pydevd.py", line 1226, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/alexisbenoist/Documents/python/papyrus/tets.py", line 23, in <module>
blob = image_to_blob(PATH)
File "/Users/alexisbenoist/Documents/python/papyrus/tets.py", line 12, in image_to_blob
pdf.alpha_channel = False
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/image.py", line 419, in wrapped
result = function(self, *args, **kwargs)
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/image.py", line 992, in alpha_channel
self.raise_exception()
File "/Users/alexisbenoist/Documents/python/papyrus/env/lib/python2.7/site-packages/wand/resource.py", line 218, in raise_exception
raise e
wand.exceptions.WandError: wand contains no images `MagickWand-1' # error/magick-image.c/MagickSetImageAlphaChannel/9504
I'm using the same virtual env in the terminal and PyCharm.
Do you guys know what could cause the problem?
Thanks,
Alexis.
I have the following celery task:
#task
def get_users_facebook_as_profile_icon(user_id, facebook_id):
logger.info('Grabbing users facebook picture')
url = "http://graph.facebook.com/%s/picture?type=large" % facebook_id
import requests
response = requests.get(url)
if response.status_code != 200:
raise Exception("Could not get facebook profile picture")
...
I have more after this, but I keep getting the following error:
"AssertionError('PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()',)"
Task was called with args: (3246, 17500596) kwargs: {}.
The contents of the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 437, in __protected_call__
return self.run(*args, **kwargs)
File "/home/ubuntu/mounzawebsite/mounza/celery_tasks/login_registration.py", line 42, in get_users_facebook_as_profile_icon
hashname = user.generate_picture_name()
File "/home/ubuntu/mounzawebsite/mounza/web/models.py", line 515, in generate_picture_name
return generate_random_name(None)
File "/home/ubuntu/mounzawebsite/mounza/web/models.py", line 40, in generate_random_name
str(random.randint(1, 99982098098908237)) +
File "/usr/lib/python2.7/dist-packages/Crypto/Random/__init__.py", line 41, in get_random_bytes
return _UserFriendlyRNG.get_random_bytes(n)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 213, in get_random_bytes
return _get_singleton().read(n)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 163, in read
return _UserFriendlyRNG.read(self, bytes)
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 122, in read
self._check_pid()
File "/usr/lib/python2.7/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 138, in _check_pid
raise AssertionError("PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()")
AssertionError: PID check failed. RNG must be re-initialized after fork(). Hint: Try Random.atfork()
I tried digging into this online, not able to find the root cause. but this is the only task where this error occurs. The only difference is that i'm downloading an image from Facebook, but I never see this issue anywhere else, including other tasks where I download images.
The URL works perfectly if I do it through a web browser, but it's only via this task it fails. Is there anything else that could contribute to this??
I have exhausted all attempts in fixing this :(
Here is why:
http://comments.gmane.org/gmane.comp.python.amqp.celery.user/3664
always run teh below:
Crypto.Random.atfork()
When a new worker process is initialized. Done and done.
I'm trying to set up an instance of Django on a debian server with django-celery talking to RabbitMQ for distributed tasks.
I can get the RabbitMQ server set up and it'll respond with a good status, but as soon as celery makes contact with RabbitMQ, it throws an error and shuts down. Here's what it looks like when I try to start a dev instance of celery:
[2013-03-08 16:59:23,707: WARNING/MainProcess] celery#myserver ready.
[2013-03-08 16:59:23,725: INFO/MainProcess] consumer: Connected to amqp://celery_rabbit#127.0.0.1:5672//rabbit_vhost.
[2013-03-08 16:59:23,734: ERROR/MainProcess] Unrecoverable error: AMQPError('Unknown AMQP method (10, 60)', None, None, None, '')
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/celery/worker/__init__.py", line 351, in start
component.start()
File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 392, in start
self.reset_connection()
File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 748, in reset_connection
self.reset_pidbox_node()
File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 687, in reset_pidbox_node
callback=self.on_control,
File "/usr/local/lib/python2.6/dist-packages/kombu/pidbox.py", line 71, in listen
consumer.consume()
File "/usr/local/lib/python2.6/dist-packages/kombu/messaging.py", line 401, in consume
self._basic_consume(T, no_ack=no_ack, nowait=False)
File "/usr/local/lib/python2.6/dist-packages/kombu/messaging.py", line 522, in _basic_consume
no_ack=no_ack, nowait=nowait)
File "/usr/local/lib/python2.6/dist-packages/kombu/entity.py", line 571, in consume
nowait=nowait)
File "/usr/local/lib/python2.6/dist-packages/amqp/channel.py", line 1766, in basic_consume
(60, 21), # Channel.basic_consume_ok
File "/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py", line 69, in wait
self.channel_id, allowed_methods)
File "/usr/local/lib/python2.6/dist-packages/amqp/connection.py", line 230, in _wait_method
self.wait()
File "/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py", line 71, in wait
return self.dispatch_method(method_sig, args, content)
File "/usr/local/lib/python2.6/dist-packages/amqp/abstract_channel.py", line 85, in dispatch_method
raise AMQPError('Unknown AMQP method %r' % (method_sig, ))
AMQPError: Unknown AMQP method (10, 60)
Just to confirm, I can check that RabbitMQ is still running afterwards:
# rabbitmqctl status
Status of node rabbit#myserver ...
[{running_applications,[{rabbit,"RabbitMQ","1.8.1"},
{mnesia,"MNESIA CXC 138 12","4.4.14"},
{os_mon,"CPO CXC 138 46","2.2.5"},
{sasl,"SASL CXC 138 11","2.1.9.2"},
{stdlib,"ERTS CXC 138 10","1.17"},
{kernel,"ERTS CXC 138 10","2.14"}]},
{nodes,[{disc,[rabbit#myserver]}]},
{running_nodes,[rabbit#myserver]}]
...done.
This is the last thing preventing me from launching my site and has me all frazzled, so any help would be greatly appreciated! Thanks.
Downgrading kombu to 2.4.7 will fix it. The rabbitmq-server is not new enough to support AMQP 0-9-1.
I ran with the same problem in Ubuntu.
It appears that (possibly depending on the Ubuntu version) the included RabbitMQ packages might be a outdated.
And the RabbitMQ installation guide states that this is quite possible. Thus they recommend installing the .deb package from their web site.