0

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
2
  • 1
    Are you using python2.7 ? If yes add the relevant tag Commented Jul 8, 2019 at 9:11
  • I'm using python 2.7.15+ Commented Jul 8, 2019 at 9:12

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.