N
N
nikitasolyny2021-03-15 00:29:08
Python
nikitasolyny, 2021-03-15 00:29:08

What to do with "connection" error?

import telebot
import pyowm

owm = pyowm.OWM("ключ", {'language': 'ru'})
bot = telebot.TeleBot("ключ")
@bot.message_handler(content_types=['text'])
def repeat_all_messages(message): 
    pogoda = owm.weather_manager()
    observation = pogoda.weather_at_place(message.text)
    w = observation.get_weather()
    temp = w.get_temperature('celsius')["temp"]
    answer = ("В городе " + message.text + "сейчас " + w.get_detailed_status() + ", температура " + str(temp) + " градусов")
    bot.send_message(message.chat.id, answer)
bot.polling(none_stop=True)<code lang="python">
</code>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-03-15
@nikitasolyny

Because to select a language, you can’t just pass a single language value, you need a complete dictionary of settings (in which we are already changing the language).

from pyowm.utils.config import get_default_config

# создаем словарь настроек по умолчанию и в нем уже меняем язык
config_dict = get_default_config()
config_dict['language'] = 'ru'
owm = pyowm.OWM("ключ", config_dict)

And do not forget that the keys are also visible in the screenshots.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question