Ad
Python Telegram Bot Error SyntaxError: Invalid Syntax
I created a simple telegram bot in python
that communicates with DialogFlow
. This is the code
#!/usr/bin/env python
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import apiai, json
updater = Updater (token = '')
dispatcher = updater.dispatcher
# Processing commands
def startCommand (bot, update):
bot.send_message (chat_id = update.message.chat_id, text = '')
def textMessage (bot, update):
request = apiai.ApiAI (''). text_request()
request.lang = 'it'
request.session_id = 'TestBot'
request.query = update.message.text
responseJson = json.loads ( request.getresponse (). read (). decode ('utf-8'))
response = responseJson ['result'] ['fulfillment'] ['speech']
if response:
bot.send_message (chat_id = update.message.chat_id, text = response)
else:
bot.send_message (chat_id = update.message.chat_id, text = '')
start_command_handler = CommandHandler ('start', startCommand)
text_message_handler = MessageHandler (Filters.text, textMessage)
dispatcher.add_handler (start_command_handler)
dispatcher.add_handler (text_message_handler)
updater.start_polling (clean = True)
updater.idle ()
When I try to start it, i have this error
Traceback (most recent call last):
File "testbot.py", line 2, in <module>
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
File "/usr/local/lib/python2.7/dist-packages/python_telegram_bot-12.0.0b1-py2.7.egg/telegram/ext/__init__.py", line 28, in <module>
from .updater import Updater
File "/usr/local/lib/python2.7/dist-packages/python_telegram_bot-12.0.0b1-py2.7.egg/telegram/ext/updater.py", line 33, in <module>
from telegram.utils.webhookhandler import (WebhookServer, WebhookAppClass)
File "/usr/local/lib/python2.7/dist-packages/python_telegram_bot-12.0.0b1-py2.7.egg/telegram/utils/webhookhandler.py", line 27, in <module>
from tornado.httpserver import HTTPServer
File "/usr/local/lib/python2.7/dist-packages/tornado-6.0.3-py2.7-linux-x86_64.egg/tornado/httpserver.py", line 144
def __init__(self, *args: Any, **kwargs: Any) -> None:
^
SyntaxError: invalid syntax
I already installed pip
in this way
sudo apt-get install python-pip
Ad
Answer
This: *args: Any
is Python3-only syntax. You've installed the latest version of tornado
which only supports Python 3+. For Python 2.7 you need to downgrade:
pip install -U tornado==5.1.1
5.1.1 is currently the latest version that supports Python 2.7.
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad