cve-portal icon indicating copy to clipboard operation
cve-portal copied to clipboard

create.py problem

Open DerickALagunes opened this issue 8 years ago • 11 comments

Hello,

Following the install steps i cant pass the part when create.py is executed i got this:

Traceback (most recent call last): File "create.py", line 3, in models.db.drop_all() File "/home/vagrant/git/cve-portal/app/virtenv/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py", line 980, in drop_all self._execute_for_all_tables(app, bind, 'drop_all') File "/home/vagrant/git/cve-portal/app/virtenv/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py", line 949, in _execute_for_all_tables app = self.get_app(app) File "/home/vagrant/git/cve-portal/app/virtenv/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py", line 922, in get_app raise RuntimeError('application not registered on db ' `RuntimeError: application not registered on db instance and no application bound to current context

Is there any problem in the code? or maybe i did something wrong before? I followed up all the steps without any problem and i had installed cve-search before too.

thanks for any advice.

DerickALagunes avatar May 26 '16 09:05 DerickALagunes

maybe this is linked to the configuration file? Is there any documentation of how to fill it?

DerickALagunes avatar May 31 '16 12:05 DerickALagunes

Hello, Probably not the configuration file. It's about Flask and the application context:

  • http://flask.pocoo.org/docs/0.11/appcontext/
  • https://stackoverflow.com/questions/9692962/flask-sqlalchemy-import-context-issue
  • https://stackoverflow.com/questions/19437883/when-scattering-flask-models-runtimeerror-application-not-registered-on-db-w

Starow avatar May 31 '16 12:05 Starow

So I have to change the code of models.db.drop_all() ? I really don't know a lot of python

DerickALagunes avatar May 31 '16 13:05 DerickALagunes

So in the end i arrived to this conclusion:

The app value is always "none" and the method connection_stack.top returns none too.

I see that from the start the default app value is none and it pass like that from method drop_all to method get_app that's when it tries connection_stack.top to get the app from there but it also returns none.

So the fact that the app value is by default "none" from the start is meant to be then something is failing with connection_stack.top the question is why it don't get the app?

DerickALagunes avatar Jun 01 '16 13:06 DerickALagunes

I was also facing the same problem, and I managed to fix it by adding this at top of create.py:

import server
server.app.app_context().push()
models.db.init_app(server.app)

mdeous avatar Jan 23 '17 16:01 mdeous

[root@ip-10-8-4-42 app]# python create.py /opt/cve-portal/app/server.py:8: ExtDeprecationWarning: Importing flask.ext.bootstrap is deprecated, use flask_bootstrap instead. from flask.ext.bootstrap import Bootstrap /opt/cve-portal/app/server.py:9: ExtDeprecationWarning: Importing flask.ext.login is deprecated, use flask_login instead. from flask.ext.login import LoginManager, current_user /opt/cve-portal/app/server.py:10: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead. from flask.ext.script import Manager /opt/cve-portal/app/models.py:8: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead. from flask.ext.sqlalchemy import SQLAlchemy /opt/cve-portal/app/models.py:10: ExtDeprecationWarning: Importing flask.ext.scrypt is deprecated, use flask_scrypt instead. from flask.ext.scrypt import generate_random_salt, generate_password_hash, check_password_hash /opt/cve-portal/app/utils.py:10: ExtDeprecationWarning: Importing flask.ext.mail is deprecated, use flask_mail instead. from flask.ext.mail import Message, Mail /opt/cve-portal/app/utils.py:11: ExtDeprecationWarning: Importing flask.ext.pymongo is deprecated, use flask_pymongo instead. from flask.ext.pymongo import PyMongo /opt/cve-portal/app/form_class.py:5: ExtDeprecationWarning: Importing flask.ext.wtf is deprecated, use flask_wtf instead. from flask.ext.wtf import Form Traceback (most recent call last): File "create.py", line 5, in models.db.drop_all() File "/usr/lib64/python2.7/site-packages/flask_sqlalchemy/init.py", line 1015, in drop_all self._execute_for_all_tables(app, bind, 'drop_all') File "/usr/lib64/python2.7/site-packages/flask_sqlalchemy/init.py", line 999, in _execute_for_all_tables op(bind=self.get_engine(app, bind), **extra) File "/usr/lib64/python2.7/site-packages/flask_sqlalchemy/init.py", line 941, in get_engine return connector.get_engine() File "/usr/lib64/python2.7/site-packages/flask_sqlalchemy/init.py", line 543, in get_engine self._engine = rv = sqlalchemy.create_engine(info, **options) File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/init.py", line 362, in create_engine return strategy.create(*args, **kwargs) File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 51, in create dialect_cls = u.get_dialect() File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/url.py", line 129, in get_dialect cls = registry.load(name) File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 194, in load (self.group, name)) sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgre

What to do?

joker2a avatar Apr 19 '17 13:04 joker2a

@joker2a this looks like a different issue. It seems sqlalchemy wants to load the postgresql engine, which it cannot find.

You are using a virtualenv, right?

Paste your pip freeze output here.

SteveClement avatar Apr 19 '17 14:04 SteveClement

Hi @SteveClement Yes i use a virtualenv

[root@ip-10-8-4-42 ~]# pip freeze alchemyjsonschema==0.4.2 appdirs==1.4.3 blinker==1.4 cairocffi==0.8.0 CairoSVG==2.0.2 cffi==1.10.0 click==6.7 config-loader==1.0.0 configparser==3.5.0 Cpyx==0.2.2.0 cssselect==1.0.1 Cython==0.25.2 defusedxml==0.5.0 dominate==2.3.1 ez-setup==0.9 feedformatter==0.5 Flask==0.12.1 Flask-Bootstrap==3.3.7.1 Flask-Login==0.2.11 Flask-Mail==0.9.1 Flask-PyMongo==0.4.1 Flask-Script==2.0.5 Flask-Scrypt==0.1.3.6 Flask-SQLAlchemy==2.2 gevent==1.2.1 greenlet==0.4.12 html5lib==0.999999999 inflect==0.2.5 irc==15.0.6 isodate==0.5.4 itsdangerous==0.24 jaraco.classes==1.4.1 jaraco.collections==1.5.1 jaraco.functools==1.15.2 jaraco.itertools==2.0.1 jaraco.logging==1.5 jaraco.stream==1.1.2 jaraco.text==1.9.2 Jinja2==2.9.6 jsonschema==2.6.0 lxml==3.7.3 MarkupSafe==1.0 module-loader==0.1.5 moduleloader==0.1.10 more-itertools==3.0.0 numpy==1.12.1 oauthlib==2.0.2 olefile==0.44 packaging==16.8 parse==1.8.0 passlib==1.7.1 Pillow==4.1.0 plugin-loader==0.1.1 psycopg2==2.7.1 pycparser==2.17 PyJWT==1.4.2 pymongo==3.4.0 pyparsing==2.2.0 Pyphen==0.9.4 pystan==2.14.0.0 python-dateutil==2.6.0 python-gnupg==0.4.0 python-libnmap==0.7.0 python-social-auth==0.3.6 python3-openid==3.1.0 pytz==2017.2 PyYAML==3.12 recordtype==1.1 redis==2.10.5 requests==2.13.0 requests-oauthlib==0.8.0 scrypt==0.8.0 six==1.10.0 sleekxmpp==1.3.2 social-auth-core==1.2.0 specter==0.2.1 SQLAlchemy==1.1.9 sqlalchemy-models==0.0.6 sqlalchemy-postgresql-json==0.5.0 sqlalchemy-redshift==0.5.0 sqlparse==0.2.3 strict-rfc3339==0.7 tempora==1.6.1 tinycss==0.4 tornado==4.4.3 urllib2-file==0.2.1 urllib3==1.20 urllib5==5.0.0 urlparse2==1.1.1 urlparse3==1.1 v==2.1.0 virtualenv==15.1.0 virtualenv-activator==0.1.2 visitor==0.1.3 WeasyPrint==0.36 webencodings==0.5.1 websocket==0.2.1 Werkzeug==0.12.1 Whoosh==2.7.4 xlrd==1.0.0

joker2a avatar Apr 20 '17 08:04 joker2a

I found 1 Bug, in config.cfg the type is wrong:

type = postgre

Does not exist. Changed it to:

type = postgresql

If you have a working postgres database, this will work, or perhaps, like in my case, give you a next error ;)

Let us know what happened next.

SteveClement avatar Apr 21 '17 11:04 SteveClement

Thanks ! I circumvented the problem with:

[Database] type = sqlite

joker2a avatar Apr 21 '17 11:04 joker2a

Ubuntu 16.04 on vbox machine.

(virtenv) ubuntu@ubuntu-16:~/cve-portal/app/config$ (virtenv) ubuntu@ubuntu-16:~/cve-portal/app$ python create.py /home/ubuntu/cve-portal/app/models.py:8: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead. from flask.ext.sqlalchemy import SQLAlchemy /home/ubuntu/cve-portal/app/models.py:9: ExtDeprecationWarning: Importing flask.ext.login is deprecated, use flask_login instead. from flask.ext.login import UserMixin, AnonymousUserMixin /home/ubuntu/cve-portal/app/models.py:10: ExtDeprecationWarning: Importing flask.ext.scrypt is deprecated, use flask_scrypt instead. from flask.ext.scrypt import generate_random_salt, generate_password_hash, check_password_hash Traceback (most recent call last): File "create.py", line 3, in models.db.drop_all() File "/home/ubuntu/cve-portal/app/virtenv/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py", line 1015, in drop_all self._execute_for_all_tables(app, bind, 'drop_all') File "/home/ubuntu/cve-portal/app/virtenv/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py", line 984, in _execute_for_all_tables app = self.get_app(app) File "/home/ubuntu/cve-portal/app/virtenv/local/lib/python2.7/site-packages/flask_sqlalchemy/init.py", line 957, in get_app 'application not registered on db instance and no application' RuntimeError: application not registered on db instance and no applicationbound to current context (virtenv) ubuntu@ubuntu-16:~/cve-portal/app$ (virtenv) ubuntu@ubuntu-16:~/cve-portal/app$ (virtenv) ubuntu@ubuntu-16:~/cve-portal/app$ (virtenv) ubuntu@ubuntu-16:~/cve-portal/app$ pip freeze blinker==1.4 click==6.7 dominate==2.3.1 Flask==0.12.2 Flask-Bootstrap==3.3.7.1 Flask-Login==0.4.0 Flask-Mail==0.9.1 Flask-PyMongo==0.5.1 Flask-Script==2.0.5 Flask-Scrypt==0.1.3.6 Flask-SQLAlchemy==2.2 Flask-WTF==0.14.2 gnupg===2.3.0-1-gadc6f0e gunicorn==19.7.1 itsdangerous==0.24 Jinja2==2.9.6 MarkupSafe==1.0 pkg-resources==0.0.0 psutil==5.2.2 pymongo==3.4.0 redis==2.10.5 scrypt==0.8.0 SQLAlchemy==1.1.10 visitor==0.1.3 Werkzeug==0.12.2 Whoosh==2.7.4 WTForms==2.1 (virtenv) ubuntu@ubuntu-16:~/cve-portal/app$

I've installed postgresql, created empty db and user. I've edited config.cfg and filled all fields in [Database] with correct values:

type = postgresql user = cveportal password = ********** hostname = localhost db_name = cveportal

And still got aforementioned errors.

vti-uplata avatar Jun 13 '17 13:06 vti-uplata