My Telegram bot aimed at retrieving Yahoo Finance stock data throws an Updater attribute error. How can this be resolved? Revised code below:
import requests
from telegram.ext import Updater, CommandHandler
from bs4 import BeautifulSoup
def fetch_stock(symbol):
url = 'https://finance.yahoo.com/quote/' + symbol
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
value = soup.find('span', {'data-test': 'qsp-price'}).text
return value
def process_command(update, context):
indices = ['^IXIC', '^GSPC']
prices = [fetch_stock(idx) for idx in indices]
reply = 'NASDAQ: ' + prices[0] + '\nS&P500: ' + prices[1]
context.bot.send_message(chat_id=update.effective_chat.id, text=reply)
if __name__ == '__main__':
api_token = 'YOUR_TOKEN_HERE'
bot_updater = Updater(api_token)
dp = bot_updater.dispatcher
dp.add_handler(CommandHandler('quote', process_command))
bot_updater.start_polling()
I encountered something similar when I was using a different version of the python-telegram-bot library. The issue often arises because the Updater class was adjusted in newer versions, and code that worked in previous versions might not be compatible anymore. I solved the problem by either updating my code to align with the latest API changes or downgrading the package to a version that supports the older functionality. In my case, adjusting the implementation to use the Application builder approach helped eliminate the error. It’s important to verify your package version and device the appropriate solution accordingly.
In my experience, the error stemmed from a mismatch between the code structure and the version of the telegram library installed. I resolved a similar issue by verifying that my environment was running a version compatible with the code example I was following. It turned out that explicitly specifying parameters like use_context and adjusting the function signatures for command handlers was necessary. Consequently, aligning the code with the version’s requirements or installing a version that supports the older API resolved the attribute error and allowed the bot to function correctly.
i had a similar problem and fixed it by installing an older version of the library. i stuck with the version where updater worked as expected. also, recheck your token and settings, they sometimes add to the issues
After struggling with a similar issue, I realized that the problem was due to a major update in the python-telegram-bot library that shifted away from some of the older constructs. In my case, the solution was to rework the bot logic entirely to align with the new asynchronous framework introduced in the recent releases. I went through the updated documentation and refactored my command handlers using the Application builder. This not only resolved the attribute error but also enhanced overall performance and reliability. It’s crucial to keep an eye on the library’s change logs and update your implementation accordingly, as the evolving API can cause these unexpected issues.