简体   繁体   中英

Python pexpect.expect() on Telegram CLI

I'm trying to make a bot for Telegram on my RPi but I'm pretty new to this. I installed Telegram Cli and pexpect.

This is my test.py file:

import pexpect

telegram = pexpect.spawn('./telegram -k tg.pub')
telegram.expect("User")
telegram.send("msg Big_Boss test")

However this give me the following error:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    telegram.expect("User*")
  File "/usr/local/lib/python2.7/dist-packages/pexpect/__init__.py", line 1451, in expect
    timeout, searchwindowsize)
  File "/usr/local/lib/python2.7/dist-packages/pexpect/__init__.py", line 1466, in expect_list
    timeout, searchwindowsize)
  File "/usr/local/lib/python2.7/dist-packages/pexpect/__init__.py", line 1554, in expect_loop
    raise EOF(str(err) + '\n' + str(self))
pexpect.EOF: End Of File (EOF). Exception style platform.

I couldnt find any good documentation about the expect function. Basically what I am trying to do is send X when someone messages me something containing Y. But I can't get the first thing working. Simply sending a command.

Here's a Pexpect tutorial , and some sample code:

source

import pexpect

calc = pexpect.spawn('bc')
calc.expect("details")
print calc.send("1+2")

output

3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM