Create database #11

Closed
opened 2022-06-02 08:47:46 +00:00 by junkscript · 10 comments
junkscript commented 2022-06-02 08:47:46 +00:00 (Migrated from github.com)

Can you explane please how to create a database for this bot?

When i try to start the bot i receive the same error every time:

  File "source/bot.py", line 25, in <module>
    from db import User, session, Product, Score
  File "/home/myserver/telegram_bot/source/db.py", line 84, in <module>
    Base.metadata.create_all(engine)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/sql/schema.py", line 4888, in create_all
    bind._run_ddl_visitor(
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3146, in _run_ddl_visitor
    with self.begin() as conn:
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3062, in begin
    conn = self.connect(close_with_result=close_with_result)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3234, in connect
    return self._connection_cls(self, close_with_result=close_with_result)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 96, in __init__
    else engine.raw_connection()
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3313, in raw_connection
    return self._wrap_pool_connect(self.pool.connect, _connection)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3280, in _wrap_pool_connect
    return fn()
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 310, in connect
    return _ConnectionFairy._checkout(self)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 868, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 476, in checkout
    rec = pool._do_get()
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/impl.py", line 146, in _do_get
    self._dec_overflow()
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/impl.py", line 143, in _do_get
    return self._create_connection()
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 256, in _create_connection
    return _ConnectionRecord(self)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 371, in __init__
    self.__connect()
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 666, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/create.py", line 590, in connect
    return dialect.connect(*cargs, **cparams)
  File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/default.py", line 597, in connect
    return self.dbapi.connect(*cargs, **cparams)
TypeError: __init__() got an unexpected keyword argument 'check_same_thread'```

Maybe it's because i didn't create the database before?
Can you explane please how to create a database for this bot? When i try to start the bot i receive the same error every time: ```Traceback (most recent call last): File "source/bot.py", line 25, in <module> from db import User, session, Product, Score File "/home/myserver/telegram_bot/source/db.py", line 84, in <module> Base.metadata.create_all(engine) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/sql/schema.py", line 4888, in create_all bind._run_ddl_visitor( File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3146, in _run_ddl_visitor with self.begin() as conn: File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3062, in begin conn = self.connect(close_with_result=close_with_result) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3234, in connect return self._connection_cls(self, close_with_result=close_with_result) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 96, in __init__ else engine.raw_connection() File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3313, in raw_connection return self._wrap_pool_connect(self.pool.connect, _connection) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/base.py", line 3280, in _wrap_pool_connect return fn() File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 310, in connect return _ConnectionFairy._checkout(self) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 868, in _checkout fairy = _ConnectionRecord.checkout(pool) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 476, in checkout rec = pool._do_get() File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/impl.py", line 146, in _do_get self._dec_overflow() File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__ compat.raise_( File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/compat.py", line 208, in raise_ raise exception File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/impl.py", line 143, in _do_get return self._create_connection() File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 256, in _create_connection return _ConnectionRecord(self) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 371, in __init__ self.__connect() File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 666, in __connect pool.logger.debug("Error on connect(): %s", e) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__ compat.raise_( File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/util/compat.py", line 208, in raise_ raise exception File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/pool/base.py", line 661, in __connect self.dbapi_connection = connection = pool._invoke_creator(self) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/create.py", line 590, in connect return dialect.connect(*cargs, **cparams) File "/home/myserver/virtualenv/telegram_bot/3.8/lib64/python3.8/site-packages/sqlalchemy/engine/default.py", line 597, in connect return self.dbapi.connect(*cargs, **cparams) TypeError: __init__() got an unexpected keyword argument 'check_same_thread'``` Maybe it's because i didn't create the database before?
H4CK3R-01 commented 2022-06-02 10:30:55 +00:00 (Migrated from github.com)

I have never seen anything like that before.
Which command did you use to start this application? Which database?

Maybe you have to set the environment variables correctly

The database should be created automatically at startup

I have never seen anything like that before. Which command did you use to start this application? Which database? Maybe you have to set the environment variables correctly The database should be created automatically at startup
FlorianKellermann commented 2022-06-02 11:22:44 +00:00 (Migrated from github.com)

Did you run the db.py file before running the bot script ? I think that might be a reason

Did you run the db.py file before running the bot script ? I think that might be a reason
H4CK3R-01 commented 2022-06-02 11:32:41 +00:00 (Migrated from github.com)

Since the db file is imported in the bot.py file you do not have to run it seperately

Since the db file is imported in the bot.py file you do not have to run it seperately
FlorianKellermann commented 2022-06-02 11:49:44 +00:00 (Migrated from github.com)

nevermind, true

nevermind, true
junkscript commented 2022-06-02 13:02:55 +00:00 (Migrated from github.com)

In the .env file I have to replace the database setting data with the one I should create, right?

I create an environment, activate it and install the requirements, then in theory I manually add the key of my bot in the .env file but I do not replace the database data because I have not created any.

I launch the script with python source / bot.py but I get the above error ...

In the .env file I have to replace the database setting data with the one I should create, right? I create an environment, activate it and install the requirements, then in theory I manually add the key of my bot in the .env file but I do not replace the database data because I have not created any. I launch the script with python source / bot.py but I get the above error ...
H4CK3R-01 commented 2022-06-02 13:17:10 +00:00 (Migrated from github.com)

i may look at it tonight or tomorrow to find out what the problem is.
Until then you can use the docker image.
Build the image using docker build .

i may look at it tonight or tomorrow to find out what the problem is. Until then you can use the docker image. Build the image using `docker build .`
H4CK3R-01 commented 2022-06-02 15:45:12 +00:00 (Migrated from github.com)

I have updated our README.
Hope the new documentation helps to deploy this telegram bot.

For further questions/problems just contact us

I have updated our [README](https://github.com/H4CK3R-01/GuessThePrice/blob/main/README.md). Hope the new documentation helps to deploy this telegram bot. For further questions/problems just contact us
FlorianKellermann commented 2022-06-02 15:46:19 +00:00 (Migrated from github.com)

@junkscript did you try it just with the mysql DATABASE_CONNECTION or also with the SQLite ?

@junkscript did you try it just with the mysql DATABASE_CONNECTION or also with the SQLite ?
junkscript commented 2022-06-02 16:04:53 +00:00 (Migrated from github.com)

Hello @FlorianKellermann and @H4CK3R-01,

i solved this problem eliminating ?check_same_thread=False from line 6 on .env file.

I created a mysql database by hand and linked it to the .env file because the script was unable to do it by itself, I deleted the reference to check_same_thread and everything worked.

There are also other errors, if you want I can continue to report them.

Hello @FlorianKellermann and @H4CK3R-01, i solved this problem eliminating `?check_same_thread=False` from line 6 on .env file. I created a mysql database by hand and linked it to the .env file because the script was unable to do it by itself, I deleted the reference to check_same_thread and everything worked. There are also other errors, if you want I can continue to report them.
H4CK3R-01 commented 2022-06-02 16:25:25 +00:00 (Migrated from github.com)

Nice to know that it's working now.

There is one known issue: We are using Gecko and Mozilla Firefox to load data from Amazon. In the Docker image it is working but we have never tested the non docker version of that.
If you have other errors, feel free to report them 😄

Nice to know that it's working now. There is one known issue: We are using Gecko and Mozilla Firefox to load data from Amazon. In the Docker image it is working but we have never tested the non docker version of that. If you have other errors, feel free to report them :smile:
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: DHBW/GuessThePrice#11
No description provided.