Ошибка выбивает не с первого запроса а с другой.
2020-10-12 10:26:34,395 (util.py:75 WorkerThread2) ERROR - TeleBot: "OperationalError occurred, args=(-1, 'MySQL Connection not available.', None)
Traceback (most recent call last):
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:\Users\Roman-Server\Desktop\phoner\phoner1.0.py", line 29, in lalala
mycursor = mydb.cursor()
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 917, in cursor
raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.
"
Traceback (most recent call last):
File "C:\Users\Roman-Server\Desktop\phoner\phoner1.0.py", line 40, in
bot.polling(none_stop=True)
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 427, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 451, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 118, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\six.py", line 703, in reraise
raise value
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:\Users\Roman-Server\Desktop\phoner\phoner1.0.py", line 29, in lalala
mycursor = mydb.cursor()
File "C:\Users\Roman-Server\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 917, in cursor
raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.
import telebot
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="123321",
database="phoner"
)
from telebot import types
TOKEN = '1238023218:AAEpKjmYholrtRmkfLXgcGlQzYxuxKKMJj9'
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=["start", "hello"])
def welcome(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item3 = types.KeyboardButton("Вести номер телефону")
markup.add(item3)
bot.send_message(message.chat.id, "Привіт, {0.first_name}!\nЯ - <b>{1.first_name}</b>, допоможу знайти тобі дані про людини".format(message.from_user, bot.get_me()),
parse_mode='html', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.chat.type == 'private':
if message.text == "Вести номер телефону":
bot.send_message(message.chat.id, "Ведіть номер телефону Зразок:+380123456789", reply_markup=None)
elif len(message.text) == 13 and message.text[0] == "+":
global number
number = message.text
print(message.text)
mycursor = mydb.cursor()
sql = "SELECT * FROM bdnumber WHERE number = %s"
mycursor.execute(sql,(number, ))
myresult = mycursor.fetchall()
for x in myresult:
print(x)
bot.send_message(message.chat.id,"Ім'я: "+x[0]+"\nНомер телефону: "+x[1]+"\nInstagram: "+x[2], reply_markup=None)
else:
bot.send_message(message.chat.id, "некоректне ведення, спробуйте ще раз", reply_markup=None)
print("Повідомлення- ", message.text, "тип-",type(message.text),"Кількість символів- ", len(message.text),"Перша цифра- ",message.text[0])
# RUN
bot.polling(none_stop=True)