TypeError: List indexes should be integers or fragments, not str

30 views Asked by At

I'm a beginner and I want to create a bot, but an error comes out:

line 83, in getWeather

weather = data['weather']['home']

TypeError:

List indexes should be integers or fragments, not str

Code:

import telebot

#of the types of telebot imports

import sqlite3  

import queries

import json

file = open('./video5451707352950524563.mp4', 'rb')

bot = telebot.TeleBot('7109333745:AAG9kZs9cEYvwazd6BP1fXh8seTv4ngY_uw')

name = "

API1 = '8e87242871c1a9169878ff4d060a0680'

@bot.message_handler(content_types=['photo'])

def photo(mes):

bot.reply_to(mes, 'This is a photo')

@bot.message_handler(content_types=['audio'])

photo definition(mes):

bot.reply_to(mes, 'This is music')

@bot.message_handler(content_types=['video'])

photo definition(mes):

bot.reply_to(mes, 'This is a video')



@bot.message_handler(commands=['weather'])

def wheater123(mes):

bot.send_message(mes.chat.id ,'enter the city:')

bot.register_next_step_handler(mes,getWeather)





@bot.message_handler(commands=['start'])

def main(mes):

con = sqlite3.connect('Primer.sql')

cur = con.cursor()

cur.execute("CREATE A TABLE IF THERE ARE NO users (AUTO-INCREMENT OF THE INTEGER PRIMARY KEY id, name VARCHAR(50), password VARCHAR(50))")

con.commit()

cur.close()

con.close()

markup = types.ReplyKeyboardMarkup()

bt1 = types.KeyboardButton('YT')

markup.string(bt1)

bot.send_message(mes.chat.id , f' sends {a message.from the user_user.company name} , I am a bot created for the user.', reply_markup=markup)

bot.send_message(mes.chat.id , "This bot uses databases", enter me")

bot.register_next_step_handler(mes,user_name)

def username(mes):

global name

name = mes.text.strip()

bot.send_message(mes.chat.id , "This bot uses databases", steam")

bot.register_next_step_handler(mes, usrpass)

def usrpass(mes):

passw = mes.text.strip()

con = sqlite3.connect('Primer.sql')

cur = con.cursor()

cur.execute(f'INSERT TO THE VALUES OF users(name, passw) ("%s","%s")'% (name,passw))

con.commit()

cur.close()

con.close()

markup = types.InlineKeyboardMarkup()

markup.add(types.InlineKeyboardButton('User Request', callback_data='users'))

bot.send_message(mes.chat.id , 'The user is registered!', reply_markup=markup)





@bot.message_handler()

def Secret(mes):

if mes.text == 'infoDev':

markup = types.InlineKeyboardMarkup()

markup.add(types.InlineKeyboardButton('Delete?', callback_data='delete'))

bot.reply_to(mes, f'{mes}', reply_markup=markup)

elif mes.text == '/start':

bot.send_message(mes.chat.id ,f'<em>Opens </em> {mes.from_user.first_name} , I <b>am a bot</b> created for <u>user</u>.',parse_mode='html')

elif mes.text == '/help':

bot.send_message(mes.chat.id,'@USet4463')

elif mes.text == "YT":

markup = types.InlineKeyboardMarkup()

markup.add(types.InlineKeyboardButton('Go over?', url='https://www.youtube.com/@ITprsYT'))

bot.reply_to(mes,'YouTube channel', reply_markup=markup)

elif mes.text.lower == 'rickroll':

file = open('./video5451707352950524563.mp4', 'rb')

bot.send_video(mes.chat.id , file)



@bot.message_handler(content_types=['text'])

def getWeather(mes):

global API 1

city = mes.text.strip().lower()

res = requests.get(f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API1}&units=metric')

data = json.loads(res.text)

city = data['name']

weather = data['weather']['main']

temp = data[main]['temp']

bot.reply_to(Ministry of Emergency Situations, f'town {city}, temperature {temperature}, weather {weather}')

@bot.callback_query_handler(function=lambda callback: True)

def callback_mes(callback):

if callback.data == 'delete':

bot.delete_message(callback.message.chat.id , callback.message.message_id)

elif callback.data == 'users':

con = sqlite3.connect('Primer.sql')

cur = con.cursor()

cur.execute("SELECT * FROM users")

users = cur.fetchall()

info = "

for me in users:

info+= name: {i[1]} Password: {i[2]}\n'

cur.close()

con.close()

bot.send_message(callback.message.chat.id , information)









bot.polling(none_stop=True)

I wanted to make a conclusion about the weather, but I didn't get it

0

There are 0 answers