Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"flask database init" fails on "Requirement.parse('MarkupSafe>=2.0'), {'Jinja2'}" #82

Open
CazYokoyama opened this issue Jun 10, 2021 · 8 comments

Comments

@CazYokoyama
Copy link

CazYokoyama commented Jun 10, 2021

Thank you for fixing #77.
I still have an installation problem.

git clone https://github.com/glidernet/ogn-python.git
cd ogn-python
pip3 install -r requirements.txt
sudo apt install -y postgresql-12-postgis-3 redis-server python3-sqlalchemy python3-flask
; logout-login
flask database init
Traceback (most recent call last):
File "/home/caz/.local/bin/flask", line 8, in
sys.exit(main())
File "/home/caz/.local/lib/python3.8/site-packages/flask/cli.py", line 990, in main
cli.main(args=sys.argv[1:])
File "/home/caz/.local/lib/python3.8/site-packages/flask/cli.py", line 596, in main
return super().main(*args, **kwargs)
File "/home/caz/.local/lib/python3.8/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/home/caz/.local/lib/python3.8/site-packages/click/core.py", line 1662, in invoke
cmd_name, cmd, args = self.resolve_command(ctx, args)
File "/home/caz/.local/lib/python3.8/site-packages/click/core.py", line 1709, in resolve_command
cmd = self.get_command(ctx, cmd_name)
File "/home/caz/.local/lib/python3.8/site-packages/flask/cli.py", line 539, in get_command
self._load_plugin_commands()
File "/home/caz/.local/lib/python3.8/site-packages/flask/cli.py", line 535, in _load_plugin_commands
self.add_command(ep.load(), ep.name)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2444, in load
self.require(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2467, in require
items = working_set.resolve(reqs, env, installer, extras=self.extras)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 792, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (MarkupSafe 1.1.0 (/usr/lib/python3/dist-packages), Requirement.parse('MarkupSafe>=2.0'), {'Jinja2'})

$ cat /usr/lib/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

You do not touch Jinja2 nor MakupSafe as below. Your code does not use them too. What am I missing?

$ git log --grep Jinja2
$ git log --grep MarkupSafe
$

@Meisterschueler
Copy link
Collaborator

Meisterschueler commented Jun 11, 2021

Hi, you have an version conflict: MarkupSafe 1.1.0 is installed, but >= 2.0 is needed. To prevend this I strongly recommend you to use virtual environments (see installation point 2).

@CazYokoyama
Copy link
Author

Meisterschueler, I still can not install ogn-python even by virtual environments. I run the following commands.

git clone https://github.com/glidernet/ogn-python.git
cd ogn-python
python3 -m venv my_environment
source my_environment/bin/activate
pip3 install wheel
pip3 install -r requirements.txt
sudo apt install -y postgresql-all
sudo apt install -y postgresql-10-postgis-2.4 redis-server python3-sqlalchemy python3-flask postgis
export OGN_CONFIG_MODULE="config/my_custom_configuration.py"
flask database init

The last command produces

(my_environment) caz@ogn-python:~/ogn-python$ flask database init
Usage: flask [OPTIONS] COMMAND [ARGS]...
Try 'flask --help' for help.
Error: No such command 'database'.

What am I missing?

@Meisterschueler
Copy link
Collaborator

Sorry, my mistake. You must also set the environment variable "FLASK_APP". I just updated the readme.

@CazYokoyama
Copy link
Author

Here are commands I run.

sudo apt-get install -y python3-venv
git clone https://github.com/glidernet/ogn-python.git
cd ogn-python
python3 -m venv my_environment
source my_environment/bin/activate
pip3 install wheel
pip3 install -r requirements.txt
sudo apt install -y postgresql-all
sudo apt install -y postgresql-10-postgis-2.4 redis-server python3-sqlalchemy python3-flask postgis
sudo -u postgres psql
create database ogn
create user postgres with encrypted password 'postgres'
grant all privileges on database ogn to postgres
#^D
export OGN_CONFIG_MODULE="config.py"
export FLASK_APP=ogn_python.py
flask database init

I have

....
File "/home/caz/ogn-python/my_environment/lib/python3.6/site-packages/psycopg2/init.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"

I am glad if you give me an advice for the person who has never administrated a database.

@Meisterschueler
Copy link
Collaborator

Do you have a postgres database "ogn" and a postgres user "postgres" with the default password "postgres"? If not, you must modify the database connection string in the config.py from postgresql://postgres:postgres@localhost:5432/ogn to postgresql://anotheruser:anotherpassword@localhost:5432/thedatabaseyoulike

@CazYokoyama
Copy link
Author

I believe "yes, I have a postgres database ogn and a postgres user postgres with the default password postgres" because you see the following lines in my previous comment.

create database ogn
create user postgres with encrypted password 'postgres'
grant all privileges on database ogn to postgres

I have not error or warning message for those 3 lines.

@Meisterschueler
Copy link
Collaborator

Hi, it is a little tricky to analyze this problem from remote... could you set a breakpoint to the code line where the errors occures and check if the password is correct?

@CazYokoyama
Copy link
Author

By the following print line,

    dsn = _ext.make_dsn(dsn, **kwargs)
    print("XXX", dsn)
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)

I have

(my_environment) caz@ogn-python:~/ogn-python$ flask database init
XXX host=localhost user=postgres password=postgres port=5432 dbname=ogn

This is the expected arguments, correct? So the problem is postgres database side. I wonder whether I configured database correctly by the following lines.

sudo -u postgres psql
create database ogn
create user postgres with encrypted password postgres
grant all privileges on database ogn to postgres
#^D

These lines are exact typing except for #^D which I type control-D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants