T
T
timurc2019-11-03 16:47:25
Python
timurc, 2019-11-03 16:47:25

An error occurs when starting the Telegram Python weather bot. What to do?

Hello everyone! I think everyone has already seen this code, I'll be honest, I took it and borrowed it. But I also edited it, in the part where answer removed the extra quotes and grouped it. But it throws a bunch of errors on startup. Tried proxy, maybe that's the issue? Did not work. I don't think vpn has anything to do with it. Most likely, the code was written crookedly.
VERSION PYTHON 3.8
All in place, pyowm and telebot downloaded. Judging from the errors, I realized that he cannot find normal code in files like connectionspool.py Help please :) Thank you!

import pyowm
import telebot

owm = pyowm.OWM('ключOpenWeatherMap', language='ru')
bot = telebot.TeleBot('ключTelegramBot')

#from telebot import apihelper # вот этот код видел у кого-то, и прикрепил. Писало, что прокси не поддерживается socks5
#apihelper.proxy = {'https':'socks5://127.0.0.1:9050'}


@bot.message_handler(content_types=['text'])
def send_echo(message):
    try:
        observation = owm.weather_at_place(message.text)
        w = observation.get_weather()
        temp = w.get_temperature('celsius')['temp']

        answer = ("В населенном пункте " + {message.text} + " сейчас " + {w.get_detailed_status()} + " °C")
        answer += ("Округленная температура равна " + {round(temp)} + " °C")

        if temp < 0:
            answer += 'Очень холодно.'
        elif temp < 5:
            answer += 'Температура довольно низкая.'
        elif temp < 15:
            answer += 'Прохладно, но в целом все хорошо.'
        else:
            answer += 'Тепло.'

        bot.send_message(message.chat.id, answer)
    except pyowm.exceptions.api_response_error.NotFoundError:
        bot.send_message(message.chat.id, 'О-ш-и-б-к-а. Введите название населенного пункта верно.')


bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin The Same, 2019-11-09
@konstantin_tot_samii

Are you from Howdy Ho?) Stupidly rewrote his code, but okay. In short, the problems are all due to telegram blocking, you need to find a normal vpn, and connect to the Internet through a wire, or, well, to the extreme Wi-Fi from the router. Try dozens of free vpn services and find one where you will have an acceptable speed for the bot to work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question