luckydonald / pytg

Python package that wraps around Telegram messenger CLI. Send and receive messages, and more.
MIT License
369 stars 76 forks source link

Unrecognized option '--permanent-peer-ids' / can't compile test branch #72

Closed Conny225 closed 8 years ago

Conny225 commented 8 years ago
/root/telegram-bot/tg/bin/telegram-cli:` unrecognized option '--permanent-peer-ids'
Traceback (most recent call last):
  File "anlage.py", line 8, in <module>
    tg = Telegram(telegram='/root/telegram-bot/tg/bin/telegram-cli', pubkey_file='/root/telegram-bot/tg/t        g-server.pub')
  File "/usr/local/lib/python2.7/dist-packages/pytg/__init__.py", line 52, in __init__
    raise AssertionError("CLI Process died.")
AssertionError: CLI Process `died.

I Need your Help. i can´t start my script.

import pytg
from pytg import Telegram
from pytg.sender import Sender
from pytg.receiver import Receiver
receiver = Receiver(host="localhost", port=4458)
sender = Sender(host="localhost", port=4458)

tg = Telegram(telegram='/root/telegram-bot/tg/bin/telegram-cli', pubkey_file='/root/telegram-bot/tg/tg-server.pub')
receiver = tg.receiver
sender = tg.sender

sender.send_msg('*******', "Hello World!")

Sorry for my Bad English

I want to Send a Message, when a sensor is false. i only Need the code to send the Message.

luckydonald commented 8 years ago

The failing part is the --permanent-peer-ids parameter (introduced in bca30085a8a34a3363b278b65261afcd013013c2) This was introduced recently.

You have currently 2 options:

1: Update telegram-cli

This requires the telegram CLI from the test branch

git clone -b test --recursive https://github.com/vysheng/tg.git tg-dev
cd tg-dev
# Now follow the normal compiling instructions.

or

2: Downgrade pytg

If you want instead to use the normal CLI, the last compatible pytg release seems to be v0.4.5, You can install that either from source (zip) or with pip install pytg==0.4.5


Time of writing this: pytg@ed8d62, v0.4.8 and tg@160231 (test)

luckydonald commented 8 years ago

If you just want to send a message, the 2nd option is probably easier.

Conny225 commented 8 years ago

thx

Conny225 commented 8 years ago
change_user_group: can't find the user telegramd to switch to
Traceback (most recent call last):
  File "anlage.py", line 13, in <module>
    sender.send_msg('Constantin_Breuer', "Hello World!")
  File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 570, in command_alias
    return self.execute_function(command_name, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 250, in execute_function
    command_name, new_args = self._validate_input(function_name, arguments)
  File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 355, in _validate_input
    function_name=function_name, number=i, type=func_type.__class__.__name__, param=str(func_type), error=str(err)))
ValueError: Error in function send_msg: parameter #1 <test> is not type UnicodeString. (Not a string.)

Iam a very bad programmer pls help me agian

luckydonald commented 8 years ago

can't find the user telegramd to switch to

It tries to run with unix user telegramd, but doesn't find such user.

You did probably start the cli with such parameter:

--username <user-name>/-U <user-name>            change uid after start
Conny225 commented 8 years ago

But why Telegramd? Where i can Change it?

luckydonald commented 8 years ago

Huh, I was assuming you set it.

Can you post the output of your program when you turn on logging?

# add this to the first lines in your file, before using pytg
import logging
logging.basicConfig(level=logging.DEBUG)
Conny225 commented 8 years ago
INFO:pytg:Starting Telegram Executable: "/root/telegram-bot/tg/bin/telegram-cli -R -W -P 4458 -k /root/telegram-b                                                                                              ot/tg/tg-server.pub --json"
DEBUG:pytg.sender:Parsing raw: Argument help - <command> (needed)
DEBUG:pytg.sender:Sending command > [disable_preview]  help
<
INFO:pytg:CLI did not responde.
change_user_group: can't find the user telegramd to switch to
DEBUG:pytg.sender:Parsing raw: Argument help - <command> (needed)
DEBUG:pytg.sender:Sending command > [disable_preview]  help
<
DEBUG:pytg.sender:Socket Connected.
DEBUG:pytg.sender:All Sent.
INFO:pytg:CLI available.
DEBUG:pytg.sender:Parsing send_msg: Argument Constantin_Breuer - <peer> (needed)
DEBUG:pytg.sender:Parsing send_msg: Argument Hello World! - <test> (needed)
DEBUG:pytg.sender:Got error
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 348, in _validate_input
    arg_value = func_type.parse(arg)
  File "/usr/local/lib/python2.7/dist-packages/pytg/argument_types.py", line 60, in parse
    raise ArgumentParseError("Not a string.")
ArgumentParseError: Not a string.
Traceback (most recent call last):
  File "anlage.py", line 17, in <module>
    sender.send_msg('Constantin_Breuer', "Hello World!")
  File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 570, in command_alias
    return self.execute_function(command_name, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 250, in execute_function
    command_name, new_args = self._validate_input(function_name, arguments)
  File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 355, in _validate_input
    function_name=function_name, number=i, type=func_type.__class__.__name__, param=str(func_type), error=str(err                                                                                              )))
ValueError: Error in function send_msg: parameter #1 <test> is not type UnicodeString. (Not a string.)
INFO:pytg.sender:Quit Sending. Not allowing sending anymore.
WARNING:pytg.sender:Terminating currently sending request.
INFO:pytg.sender:Currently not Sending.
INFO:pytg:Closing Connections.
DEBUG:pytg:Closing sender.
DEBUG:pytg.sender:Already did quit Sending. Not allowing sending.
WARNING:pytg.sender:Terminating currently sending request.
INFO:pytg.sender:Currently not Sending.
DEBUG:pytg:Closing sender.
DEBUG:pytg.receiver:receiver thread existing: Not created.
INFO:pytg:Asking to CLI to stop.
DEBUG:pytg:Sender already stopped. Unable to issue safe_quit or quit to exit via socket.
INFO:pytg:CLI did stop (0).
DEBUG:pytg.sender:Already did quit Sending. Not allowing sending.
INFO:pytg.sender:Quit Sending. Not allowing sending anymore.
WARNING:pytg.sender:Terminating currently sending request.
INFO:pytg.sender:Currently not Sending.
luckydonald commented 8 years ago

It gets the -k /root/telegram-b parameter, that is the problem. That is the Public Key you specified.

# location
tg/tg-server.pub  # the key file. 
tg/server.pub      # this one is possible too.
tg/bin/telegram-cli  # the executable.

In your case probably located in /root/telegram-bot/tg/server.pub.

You can verify yourself, if the cli will run, or the error is in pytg, by executing the stuff directly behind Starting Telegram Executable:. Also please wrap the code in code blocks, that improves readability even more.

```python
YOUR CODE
```
luckydonald commented 8 years ago

Meaning the pubkey_file parameter of Telegram( ... ) should probably be: pubkey_file="/root/telegram-bot/tg/server.pub"

Conny225 commented 8 years ago

After trying too start it with this Parameters,

-R -W -P 4458 -k /root/telegram-b

it stuck at this Point.

Loading plugin location Loading plugin media Loading plugin plugins Loading plugin channels Loading plugin set Loading plugin stats Loading plugin time Loading plugin version Loading plugin weather Loading plugin xkcd Loading plugin youtube Data loaded from file data/google.lua

luckydonald commented 8 years ago

That certainly is not coming from pytg or the telegram-cli. What bot are you using? Also, google.lua indicates you are using lua, but this is using python.

Conny225 commented 8 years ago

i didnt use any bot. I only want to use my bot

luckydonald commented 8 years ago

You are loading plugins, that was your log said. both pytg and the cli have no such plugins. You need to find where they come from, they are not part of pytg.

ziban commented 8 years ago

I get the same errors too.

luckydonald commented 8 years ago

Maybe it is the CLI then... Strange... Did you disable lua support while running configure?

ziban commented 8 years ago

I moved on to Ubuntu, and downgraded the version of pytg to make it work.

luckydonald commented 8 years ago

@ziban please help me locate that issue. What was your system before? Did you disable liblua?

ziban commented 8 years ago

I was on mac. To reproduce the error, use Python 2.7.10, and install it using the standard instructions. I downgraded and also installed the test version but it did not work. The only thing I did not do was disable liblua. I will try to do that today during the day (2 a.m right now)

luckydonald commented 8 years ago

It seems ou already tried https://github.com/vysheng/tg/issues/1014 and https://github.com/vysheng/tg/issues/996 Yeah, timezones are a stange invention...

luckydonald commented 8 years ago

@ziban you could try my compiled binary: tg binaries

ziban commented 8 years ago

I could not make the binaries to work too. The error I got was dyld: Library not loaded: /usr/local/lib/libreadline.6.dylib Referenced from: /Users/collo/Desktop/Classwork/COMP150INT/project/tg/bin/telegram-cli Reason: image not found Trace/BPT trap: 5.
Let me try to disable liblua and see how it would respond

ziban commented 8 years ago

I still get the initial error when I disable liblua.

luckydonald commented 8 years ago

@ziban I think that is libreadline as seen in https://github.com/vysheng/tg/issues/199#issuecomment-66763098

Nanoseb commented 8 years ago

This issue is no longer relevant because the dev branch of telegram-cli have been merged to master.

luckydonald commented 8 years ago

@Nanoseb thanks for the note.

youngeunkwon commented 7 years ago

Did you guys solved this problem? same problem plz help :( I started this

from pytg.sender import Sender

sender = Sender(host="localhost",port=4458) sender.send_msg("youngeun_kwon","hello")

and here is the error.

Traceback (most recent call last): File "msgtest.py", line 5, in sender.send_msg("youngeun_kwon","hello") File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 630, in command_alias File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 274, in execute_function File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 414, in _validate_input ValueError: Error in function send_msg: parameter #1 is not type UnicodeString. (Not a string.)

luckydonald commented 7 years ago

You need unicode. You have 3 options:

youngeunkwon commented 7 years ago

from pytg.sender import Sender

sender = Sender(host="localhost",port=4458) sender.send_msg(u"youngeun_kwon",u"hello")

u mean like this?

Traceback (most recent call last): File "msgtest.py", line 5, in sender.send_msg(u"youngeun_kwon",u"hello") File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 630, in command_alias File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 318, in execute_function File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 485, in _do_send pytg.exceptions.ConnectionError: Could not establish connection to the cli port, failed after 3 tries.

I got this :(

luckydonald commented 7 years ago

@youngeunkwon This means, you don't have a CLI connected. Did you run telegram from the code? Like in the Documentation: https://github.com/luckydonald/pytg#start-telegram

youngeunkwon commented 7 years ago

I know I have to start telegram-cli in json mode port 4458, but I don't know how

luckydonald commented 7 years ago

@youngeunkwon You can let it run on default, and turn on logging. to see how it will be launched: https://github.com/luckydonald/pytg#in-case-of-errors

youngeunkwon commented 7 years ago

from pytg import Telegram tg = Telegram( telegram="/home/pi/tg/bin/telegram-cli", pubkey_file="/home/pi/tg/tg-server.pub") receiver = tg.receiver sender = tg.sender

from pytg.sender import Sender

sender = Sender(host="localhost",port=4458) sender.send_msg(u"youngeun_kwon",u"hello")

start Telegram-cli like this? I got

Traceback (most recent call last): File "msgtest.py", line 11, in sender.send_msg(u"youngeun_kwon",u"hello") File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 630, in command_alias File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 354, in execute_function pytg.exceptions.FailException: Error 38: u'can not parse arg #1' (command u"[disable_preview] msg youngeun_kwon 'hello'\n")

luckydonald commented 7 years ago

@youngeunkwon If you start the CLI manually again, with the command arguments as seen in the debug mode, does sending it manually in the CLI work? So msg youngeun_kwon "hello"?

youngeunkwon commented 7 years ago
bin/telegram-cli -k tg-server.pub --json -P 4458 -W
Telegram-cli version 1.4.1, Copyright (C) 2013-2015 Vitaly Valtman
Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show_license' for details.
Telegram-cli uses libtgl version 2.1.0
Telegram-cli includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit. (http://www.openssl.org/)
I: config dir=[/home/pi/.config/telegram-cli]
> msg youngeun_kwon "hello?"
{"text": "hello?", "event": "message", "id": "010000009162cd10880000000000000006a4c20e3fb5f96c", "out": true, "flags": 16643, "from": {"id": "$010000009162cd1006a4c20e3fb5f96c", "phone": "821029061008", "peer_type": "user", "peer_id": 281895569, "print_name": "youngeun_kwon", "last_name": "kwon", "flags": 720897, "first_name": "youngeun", "username": "yskwon"}, "date": 1478391342, "to": {"id": "$010000009162cd1006a4c20e3fb5f96c", "phone": "821029061008", "peer_type": "user", "peer_id": 281895569, "print_name": "youngeun_kwon", "last_name": "kwon", "flags": 720897, "first_name": "youngeun", "username": "yskwon"}, "unread": true, "service": false}
{"result": "SUCCESS"}
> 

you mean this? Yeah this works

luckydonald commented 7 years ago

You can probably try to replace youngeun_kwon with chat#281895569 (id of peer) or @ yskwon (username).

youngeunkwon commented 7 years ago

from pytg import Telegram tg = Telegram( telegram="/home/pi/tg/bin/telegram-cli", pubkey_file="/home/pi/tg/tg-server.pub") receiver = tg.receiver sender = tg.sender

from pytg.sender import Sender

sender = Sender(host="localhost",port=4458) sender.send_msg(u"chat#281895569",u"hello")

u mean this? I got this

Traceback (most recent call last): File "msgtest.py", line 11, in <module> sender.send_msg(u"chat#281895569",u"hello") File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 630, in command_alias File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 354, in execute_function pytg.exceptions.FailException: Error 38: u'can not parse arg #1' (command u"[disable_preview] msg chat#281895569 'hello'\n")

luckydonald commented 7 years ago

Could you try [disable_preview] msg chat#281895569 'hello' manually again?

youngeunkwon commented 7 years ago

msg chat#28185569 'hello' {"error": "can not parse arg #1", "result": "FAIL", "error_code": 38}

like this?

luckydonald commented 7 years ago

huh. maybe it is chatid#28185569 now. Try [disable_preview] msg youngeun_kwon 'hello' With the [disable_preview] part

youngeunkwon commented 7 years ago

msg youngeun_kwon 'hello' {"event": "message", "id": "010000009162cd10890000000000000006a4c20e3fb5f96c", "from": {"id": "$010000009162cd1006a4c20e3fb5f96c", "peer_type": "user", "peer_id": 281895569, "print_name": "youngeun_kwon", "first_name": "youngeun", "flags": 720897, "last_name": "kwon", "phone": "821029061008", "username": "yskwon"}, "flags": 16643, "text": "hello", "to": {"id": "$010000009162cd1006a4c20e3fb5f96c", "peer_type": "user", "peer_id": 281895569, "print_name": "youngeun_kwon", "first_name": "youngeun", "flags": 720897, "last_name": "kwon", "phone": "821029061008", "username": "yskwon"}, "out": true, "unread": true, "service": false, "date": 1478392342} {"result": "SUCCESS"}

weird. it works

youngeunkwon commented 7 years ago

Traceback (most recent call last): File "msgtest.py", line 11, in sender.send_msg(u"youngeun_kwon",u"hello") File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 630, in command_alias File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 354, in execute_function pytg.exceptions.FailException: Error 38: u'can not parse arg #1' (command u"[disable_preview] msg youngeun_kwon 'hello'\n")

youngeunkwon commented 7 years ago

but this doesn't hmm... I can't understand

luckydonald commented 7 years ago

This means something in the cli might have changed, rendering [disable_preview] unusable. Please open a new issue with that.

luckydonald commented 7 years ago

It actually still seems to exist in the cli. interface.c:2248

youngeunkwon commented 7 years ago

Then you mean I can't make it work?

luckydonald commented 7 years ago

I don't know. As I am not using the CLI anywhere anymore (switched to using the bot api with pytgbot) I can't really help in detail, sorry. Still, maybe you can keep us updated on your findings?

youngeunkwon commented 7 years ago

Sure. I'm a highschool student and I'm doing a little project I want to talk with bot messenger to send me some pictures of my house or text me for gas stove alarms. can you recommend me some other ways to make my project work?

youngeunkwon commented 7 years ago

And thx for your advise though.

luckydonald commented 7 years ago

@youngeunkwon Yeah, if the bot api is available to you, try that instead. The mentioned pytgbot library. If you need help with that, just join me on telegram: https://telegram.me/pytg_group