#๐Ÿ”’ python bot telegram help please

36 messages ยท Page 1 of 1 (latest)

mystic meadowBOT
#

@strange bay

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

strange bay
#

please help me

#

Traceback (most recent call last):
File "/Users/mohamedmaatoug/Documents/greed/venv/lib/python3.9/site-packages/telegram/ext/dispatcher.py", line 447, in process_update
handler.handle_update(update, self, check, context)
File "/Users/mohamedmaatoug/Documents/greed/venv/lib/python3.9/site-packages/telegram/ext/handler.py", line 160, in handle_update
return self.callback(update, context)
File "/Users/mohamedmaatoug/Documents/greed/dadad.py", line 100, in user_clicked
send_dm(update, context, int(user_id))
File "/Users/mohamedmaatoug/Documents/greed/dadad.py", line 126, in send_dm
cursor.execute("SELECT subscription_start_date, subscription_end_date FROM users WHERE user_id=?", (user_id,))
sqlite3.OperationalError: no such column: subscription_start_date

native willow
#

it looks like you are trying to access a a column in an sqlite database that does not exists

#

make sure you spelled the column correctly and that you created the column bevore trying to access them

strange bay
native willow
#

!paste

mystic meadowBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

native willow
#

but by the way you should learn to read error messages it is really important for programming. the error tells you what is wrong and where the error occurs

strange bay
native willow
strange bay
#

please if you can help me to sort this thing out, I would like to be able to store the subscription start and end dates and then retrieve all the data in a CSV to be able to send an automatic reminder message 1- 3-5 day before end date

strange bay
native willow
#
cursor.execute("SELECT subscription_start_date, subscription_end_date FROM users WHERE user_id=?", (user_id,))

i guess you wanted to put a % instead of a ?

native willow
#

for the old string format method you need to use a %

#

i guess this is what you are trying to do?

strange bay
#

bottom I don't really know actually

native willow
#

you want the variable user_id in the sql querry, but you are putting an ? there

#

instead you should put a %

#

because that is the syntax of the old method of formatting strings

strange bay
#

I want the stock information in the database and then retrieve it in a csv file

native willow
#

or is the ? intentional?

strange bay
#

do you know how to create a telegram autoshop?

native willow
#

no

#

but you could enter the new error message

#

you said you fixed the column but you still getting an sql error?

strange bay
#

Traceback (most recent call last):
File "/Users/mohamedmaatoug/Documents/greed/venv/lib/python3.9/site-packages/telegram/ext/dispatcher.py", line 447, in process_update
handler.handle_update(update, self, check, context)
File "/Users/mohamedmaatoug/Documents/greed/venv/lib/python3.9/site-packages/telegram/ext/handler.py", line 160, in handle_update
return self.callback(update, context)
File "/Users/mohamedmaatoug/Documents/greed/dadad.py", line 35, in start
cursor.execute("INSERT INTO users (user_id, first_name, subscription_start_date, subscription_end_date) VALUES (?, ?, ?, ?)",
sqlite3.OperationalError: table users has no column named subscription_start_date
2024-02-18 21:01:02,917 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
Traceback (most recent call last):
File "/Users/mohamedmaatoug/Documents/greed/venv/lib/python3.9/site-packages/telegram/ext/dispatcher.py", line 447, in process_update
handler.handle_update(update, self, check, context)
File "/Users/mohamedmaatoug/Documents/greed/venv/lib/python3.9/site-packages/telegram/ext/handler.py", line 160, in handle_update
return self.callback(update, context)
File "/Users/mohamedmaatoug/Documents/greed/dadad.py", line 58, in list_users
cursor.execute("SELECT subscription_start_date, subscription_end_date FROM users WHERE user_id=?", (user_id,))
UnboundLocalError: local variable 'user_id' referenced before assignment

native willow
#

ok the variable user_id is not assigned but you are trying to use the variable

strange bay
#

what should I do then?

native willow
#

actually you are getting before that error this error

cursor.execute("INSERT INTO users (user_id, first_name, subscription_start_date, subscription_end_date) VALUES (?, ?, ?, ?)",
sqlite3.OperationalError: table users has no column named subscription_start_date

#

so somehow the table has at this point no column called subscription_start_date

native willow
#

I'm sorry, maybe someone who has used sqlite with python more often should help

mystic meadowBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.