Написали бота на винде, все прекрасно работает, поставили на мак, выдает ошибку подключения к хосту, не понимаем в чем дело. Текст программы прикрепляю ниже. Скрины с ошибками тоже.
import re
import os
import sqlite3
from random import choice
from aiogram import Bot, Dispatcher, types
from aiogram.utils.keyboard import ReplyKeyboardBuilder, KeyboardButton, InlineKeyboardBuilder, InlineKeyboardButton
from aiogram.types import FSInputFile
token = "тут наш токен"
bot = Bot(token=token, parse_mode='HTML')
dp = Dispatcher()
db = sqlite3.connect('data.db')
sql = db.cursor()
sql.execute("""
CREATE TABLE IF NOT EXISTS users (
id BIGINT PRIMARY KEY,
username TEXT NOT NULL,
create_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
sql.execute("""
CREATE TABLE IF NOT EXISTS themes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL DEFAULT '',
course INTEGER DEFAULT 1
)
""")
sql.execute("""
CREATE TABLE IF NOT EXISTS logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id BIGINT,
variant_number INTEGER,
theme_id INTEGER,
create_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (theme_id) REFERENCES themes(id)
)
""")
db.commit()
@dp.message(commands=['start'])
async def on_start(message: types.Message):
user = message.from_user
sql.execute("INSERT INTO users (id, username) VALUES (?,?) ON CONFLICT (id) DO UPDATE SET username=?",
(user.id, user.username, user.username))
db.commit()
markup = ReplyKeyboardBuilder()
for i in range(1, 5):
markup.add(KeyboardButton(text=f'{i} Курс'))
markup.adjust(2)
await bot.send_message(chat_id=user.id,
text='Добро пожаловать...\n<code>Designed by i923b</code>',
reply_markup=markup.as_markup(resize_keyboard=True))
@dp.message(lambda m: re.match('[1-4] Курс', m.text))
async def get_themes(message: types.Message):
course = re.search('\d', message.text)[0]
sql.execute("SELECT id, title FROM themes WHERE course = ?",(course,))
rows = sql.fetchall()
markup = InlineKeyboardBuilder()
for id, title in rows:
markup.row(InlineKeyboardButton(text=title, callback_data=f"get_task-{id}"))
await bot.send_message(message.from_user.id, text='Выберите тему:', reply_markup=markup.as_markup())
@dp.callback_query(lambda call: call.data.startswith('get_task'))
async def task_handler(call: types.callback_query):
theme_id = call.data.split('-')[-1]
user_id = call.from_user.id
sql.execute("SELECT title FROM themes WHERE id = ?", (theme_id,))
theme = sql.fetchone()[0]
files = os.listdir(theme)
variant = choice(files)
variant_number = variant.split('.')[0]
await bot.send_photo(user_id, caption=f'Ваш вариант: {variant_number}', photo=FSInputFile(path=os.path.join(theme, variant)))
sql.execute("INSERT INTO logs (user_id, variant_number, theme_id) VALUES (?, ?, ?)", (user_id, variant_number, theme_id))
db.commit()
dp.run_polling(bot)
Скриншот фрагмента кода удалён модератором.