My current code is returning an error that seems related to psycopg2. If anyone might know, I’ve looked everywhere and can’t seem to find a solution to this
my code:from telegram.ext import (Updater, CommandHandler, ConversationHandler, MessageHandler, Filters, CallbackContext)
from telegram import KeyboardButton, ReplyKeyboardMarkup, Update
from data_source import DataSource
import os
import threading
import time
import datetime
ADD_REMINDER_TEXT = ‘add a reminder’
INTERVAL = 30
TOKEN = os.getenv(“TOKEN”)
ENTER_MESSAGE, ENTER_TIME = range(2)
datasource = DataSource(os.environ.get(“DATABASE_URL”))
def start_handler(update, context):
update.message.reply_text(“Hello, Creator!”, reply_markup=add_reminder_button())
def add_reminder_button():
keyboard = [[KeyboardButton(ADD_REMINDER_TEXT)]]
return ReplyKeyboardMarkup(keyboard)
def add_reminder_handler(update: Update, context: CallbackContext):
update.message.reply_text(“please enter a message of the reminder:”)
return ENTER_MESSAGE
def enter_message_handler(update: Update, context: CallbackContext):
update.message.reply_text(“please enter a time when bot should remind:”)
context.user_data[“message_text”] = update.message.text
return ENTER_TIME
def enter_time_handler(update: Update, context: CallbackContext):
message_text = context.user_data[“message_text”]
time = datetime.datetime.strptime(update.message.text, “%d/%m/%Y %H:%M”)
message_data = datasource.create_reminder(update.message.chat_id, message_text, time)
update.message.reply_text("your reminder: " + message_data.repr())
return CommandHandler.END
def start_check_reminders_task():
thread = threading.Thread(target=check_reminders, args=())
thread.daemon = True
thread.start()
def check_reminders():
while True:
for reminder_data in datasource.get_all_reminders():
if reminder_data.should_be_fired():
datasource.fire_reminder(reminder_data.reminder_id)
updater.bot.send_message(reminder_data.chat_id, reminder_data.message)
time.sleep(INTERVAL)
if name == ‘main’:
updater = Updater(TOKEN, use_context=True)
updater.dispatcher.add_handler(CommandHandler(“start”, start_handler))
conv_handler = ConversationHandler(
entry_points=[MessageHandler(Filters.regex(ADD_REMINDER_TEXT), add_reminder_handler)],
states={
ENTER_MESSAGE: [MessageHandler(Filters.all, enter_message_handler)],
ENTER_TIME: [MessageHandler(Filters.all, enter_time_handler)]
},
fallbacks=
)
updater.dispatcher.add_handler(conv_handler)
datasource.create_tables()
updater.start_polling()
start_check_reminders_task()
returns:
/Users/aao/.pyenv/versions/3.9.2/bin/python /Users/aao/Desktop/directory/documents/coding_macbook_air/pythonvenvsdk/main.py
invalid dsn: missing “=” after “udemy_telegram” in connection info string
Traceback (most recent call last):
File “/Users/aao/Desktop/directory/documents/coding_macbook_air/pythonvenvsdk/main.py”, line 64, in
datasource.create_tables()
File “/Users/aao/Desktop/directory/documents/coding_macbook_air/pythonvenvsdk/data_source.py”, line 53, in create_tables
raise error
File “/Users/aao/Desktop/directory/documents/coding_macbook_air/pythonvenvsdk/data_source.py”, line 45, in create_tables
conn = self.get_connection()
File “/Users/aao/Desktop/directory/documents/coding_macbook_air/pythonvenvsdk/data_source.py”, line 24, in get_connection
return psycopg2.connect(self.database_url, sslmode=‘allow’)
File “/Users/aao/.pyenv/versions/3.9.2/lib/python3.9/site-packages/psycopg2/init.py”, line 121, in connect
dsn = _ext.make_dsn(dsn, **kwargs)
File “/Users/aao/.pyenv/versions/3.9.2/lib/python3.9/site-packages/psycopg2/extensions.py”, line 159, in make_dsn
tmp = parse_dsn(dsn)
psycopg2.ProgrammingError: invalid dsn: missing “=” after “udemy_telegram” in connection info string
is it possible psycopg2 is bugged? just a thought