Better Error Handling for ValueError: invalid literal for int() with base 10: 'None'
iporollo opened this issue · 0 comments
iporollo commented
Description
Seeing an error when running the application locally with flask run
flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "/Users/ivanporollo/Desktop/monosi/.venv/bin/flask", line 33, in <module>
sys.exit(load_entry_point('Flask==2.0.2', 'console_scripts', 'flask')())
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/Flask-2.0.2-py3.9.egg/flask/cli.py", line 994, in main
cli.main(args=sys.argv[1:])
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/Flask-2.0.2-py3.9.egg/flask/cli.py", line 600, in main
return super().main(*args, **kwargs)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/click-8.0.4-py3.9.egg/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/click-8.0.4-py3.9.egg/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/click-8.0.4-py3.9.egg/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/click-8.0.4-py3.9.egg/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/click-8.0.4-py3.9.egg/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/click-8.0.4-py3.9.egg/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/Flask-2.0.2-py3.9.egg/flask/cli.py", line 849, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/Flask-2.0.2-py3.9.egg/flask/cli.py", line 324, in __init__
self._load_unlocked()
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/Flask-2.0.2-py3.9.egg/flask/cli.py", line 350, in _load_unlocked
self._app = rv = self.loader()
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/Flask-2.0.2-py3.9.egg/flask/cli.py", line 410, in load_app
app = locate_app(self, import_name, None, raise_if_not_found=False)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/Flask-2.0.2-py3.9.egg/flask/cli.py", line 260, in locate_app
__import__(module_name)
File "/Users/ivanporollo/Desktop/monosi/src/server/__init__.py", line 10, in <module>
from server.middleware import middleware
File "/Users/ivanporollo/Desktop/monosi/src/server/middleware/__init__.py", line 3, in <module>
from .scheduler import init_scheduler
File "/Users/ivanporollo/Desktop/monosi/src/server/middleware/scheduler.py", line 4, in <module>
from server.config import Config
File "/Users/ivanporollo/Desktop/monosi/src/server/config.py", line 22, in <module>
class BaseConfig:
File "/Users/ivanporollo/Desktop/monosi/src/server/config.py", line 36, in BaseConfig
SCHEDULER_JOBSTORES = {"default": SQLAlchemyJobStore(url=SQLALCHEMY_DATABASE_URI, tablename="msi_jobs")}
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/APScheduler-3.9.1-py3.9.egg/apscheduler/jobstores/sqlalchemy.py", line 52, in __init__
self.engine = create_engine(url, **(engine_options or {}))
File "<string>", line 2, in create_engine
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
return fn(*args, **kwargs)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 530, in create_engine
u = _url.make_url(url)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/sqlalchemy/engine/url.py", line 715, in make_url
return _parse_rfc1738_args(name_or_url)
File "/Users/ivanporollo/Desktop/monosi/.venv/lib/python3.9/site-packages/sqlalchemy/engine/url.py", line 771, in _parse_rfc1738_args
components["port"] = int(components["port"])
ValueError: invalid literal for int() with base 10: 'None'
Expected behavior
This error occurs because local environment variables have not been set for the Monosi database. To solve this error, you need to set the following environment variables in the shell:
export DB_USER=<USER>
export DB_PASSWORD=<PASSWORD>
export DB_HOST=<HOST>
export DB_PORT=<PORT>
export DB_DATABASE=<DATABASE>
export DB_SCHEMA=<SCHEMA>
There should be better error handling to notify the user that their environment variables have not been set.
Steps to reproduce
- Clone the monosi repository
- Follow the monosi setup instructions for local environment
- Run the server through
flask run
- Observe error