nickjj / build-a-saas-app-with-flask

Learn how to build a production ready web app with Flask and Docker.
https://buildasaasappwithflask.com
MIT License
954 stars 185 forks source link

Internal sever error and db reset issue on Mac #29

Closed vblackburn closed 8 years ago

vblackburn commented 8 years ago

when trying to buy a 'gold package' from catwatch I got an internal server error (I think the problem happened with the POST request)

I shut down the app and attempted to start it up again but when running

run db reset catwatch catwatch_test

i got this error;

Error response from daemon: no such id: dropdb
Error response from daemon: no such id: dropdb
Error response from daemon: no such id: psql
Error response from daemon: no such id: createdb
Error response from daemon: no such id: createdb
Traceback (most recent call last):
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/bin/run", line 9, in <module>
    load_entry_point('Commands-to-help-manage-your-project==1.0', 'console_scripts', 'run')()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/click/core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/click/core.py", line 644, in main
    rv = self.invoke(ctx)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/click/core.py", line 991, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/click/core.py", line 991, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/click/core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "/Users/victoriaferguson/dev/docker/myapp/website/cli/commands/cmd_db.py", line 226, in reset
    ctx.invoke(create, databases=databases)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "/Users/victoriaferguson/dev/docker/myapp/website/cli/commands/cmd_db.py", line 199, in create
    return db.create_all()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 895, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 887, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), **extra)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/sql/schema.py", line 3687, in create_all
    tables=tables)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1855, in _run_visitor
    with self._optional_conn_ctx_manager(connection) as conn:
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1848, in _optional_conn_ctx_manager
    with self.contextual_connect() as conn:
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2039, in contextual_connect
    self._wrap_pool_connect(self.pool.connect, None),
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2078, in _wrap_pool_connect
    e, dialect, self)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1405, in _handle_dbapi_exception_noconnection
    exc_info
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2074, in _wrap_pool_connect
    return fn()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 376, in connect
    return _ConnectionFairy._checkout(self)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 713, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 480, in checkout
    rec = pool._do_get()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 1060, in _do_get
    self._dec_overflow()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 1057, in _do_get
    return self._create_connection()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 323, in _create_connection
    return _ConnectionRecord(self)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 449, in __init__
    self.connection = self.__connect()
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/pool.py", line 607, in __connect
    connection = self.__pool._invoke_creator(self)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 97, in connect
    return dialect.connect(*cargs, **cparams)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 385, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
    Is the server running on host "192.168.99.100" and accepting
    TCP/IP connections on port 5432?

The docker daemon is running (verified it by running hello-world again) and I have check the ip address using;

docker-machine ip default

Any suggestions on how I might fix this and what is causing it ?

EDIT - Following is the error that is arises when I try to process payment in the app;

11:29:18 web.1    | POST "/subscription/create" in 1186ms for 127.0.0.1
11:29:18 web.1    | [2015-12-09 11:29:18 +0000] [23159] [ERROR] Error handling request
11:29:18 web.1    | Traceback (most recent call last):
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
11:29:18 web.1    |     self.handle_request(listener, req, client, addr)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 171, in handle_request
11:29:18 web.1    |     respiter = self.wsgi(environ, resp.start_response)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
11:29:18 web.1    |     return self.wsgi_app(environ, start_response)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/docker/myapp/website/catwatch/lib/http_method_override_middleware.py", line 42, in __call__
11:29:18 web.1    |     return self.app(environ, start_response)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/werkzeug/contrib/fixers.py", line 152, in __call__
11:29:18 web.1    |     return self.app(environ, start_response)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
11:29:18 web.1    |     response = self.make_response(self.handle_exception(e))
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
11:29:18 web.1    |     reraise(exc_type, exc_value, tb)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
11:29:18 web.1    |     response = self.full_dispatch_request()
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/app.py", line 1479, in full_dispatch_request
11:29:18 web.1    |     response = self.process_response(response)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/app.py", line 1693, in process_response
11:29:18 web.1    |     self.save_session(ctx.session, response)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/app.py", line 837, in save_session
11:29:18 web.1    |     return self.session_interface.save_session(self, session, response)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/sessions.py", line 326, in save_session
11:29:18 web.1    |     val = self.get_signing_serializer(app).dumps(dict(session))
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/itsdangerous.py", line 565, in dumps
11:29:18 web.1    |     payload = want_bytes(self.dump_payload(obj))
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/itsdangerous.py", line 847, in dump_payload
11:29:18 web.1    |     json = super(URLSafeSerializerMixin, self).dump_payload(obj)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/itsdangerous.py", line 550, in dump_payload
11:29:18 web.1    |     return want_bytes(self.serializer.dumps(obj))
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/sessions.py", line 85, in dumps
11:29:18 web.1    |     return json.dumps(_tag(value), separators=(',', ':'))
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/json.py", line 126, in dumps
11:29:18 web.1    |     rv = _json.dumps(obj, **kwargs)
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 250, in dumps
11:29:18 web.1    |     sort_keys=sort_keys, **kw).encode(obj)
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 209, in encode
11:29:18 web.1    |     chunks = list(chunks)
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 434, in _iterencode
11:29:18 web.1    |     for chunk in _iterencode_dict(o, _current_indent_level):
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
11:29:18 web.1    |     for chunk in chunks:
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
11:29:18 web.1    |     for chunk in chunks:
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
11:29:18 web.1    |     for chunk in chunks:
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
11:29:18 web.1    |     for chunk in chunks:
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 442, in _iterencode
11:29:18 web.1    |     o = _default(o)
11:29:18 web.1    |   File "/Users/victoriaferguson/dev/virtualenvs/catwatch/lib/python2.7/site-packages/flask/json.py", line 83, in default
11:29:18 web.1    |     return _json.JSONEncoder.default(self, o)
11:29:18 web.1    |   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 184, in default
11:29:18 web.1    |     raise TypeError(repr(o) + " is not JSON serializable")
11:29:18 web.1    | TypeError: InvalidRequestError(u'No such plan: gold',) is not JSON serializable
nickjj commented 8 years ago

Let's start with the second error.

Have you ran run stripe sync_plans? This creates the plans initially. The plans can be found (and modified) in https://github.com/nickjj/build-a-saas-app-with-flask/blob/master/config/settings.py#L122.

vblackburn commented 8 years ago

running the stripe sync fixed the second problem and the first problem seems to have just stopped for no apparent reason, thanks

nickjj commented 8 years ago

If you get the first issue again, or can reproduce it please let me know.

Perhaps the Docker VM wasn't running when you tried to connect? You need to always launch the Docker terminal.