Error in sending message - Error 38: 'can not parse arg #1' with [disable_preview]
The problem
I have simple script that sending a message, but sometimes it sends message, sometimes not
Your environment
Fill out your used versions:
| Component | Version |
|---|---|
| python | 3.4.3 |
| pytg | 0.4.10 |
| OS | Ubuntu 14.04.2 LTS |
Steps to reproduce
my code is:
import logging
logging.basicConfig(level=logging.DEBUG)
import time
from pytg import Telegram
d = open('/root/stock/stocks.txt', 'a+')
tg = Telegram(telegram="/root/tg2/bin/telegram-cli", pubkey_file="/root/tg2/tg-server.pub")
sender = tg.sender
sender.send_msg("miaow2", "/stock")
time.sleep(3)
histo = sender.history("miaow2", limit=0, offset=1)
stock = histo[39]
d.write(stock['text'] + '\n')
sender.safe_quit()
d.close()
Actual behaviour
Debug for fail to send message
INFO:pytg:Starting Telegram Executable: "/root/tg2/bin/telegram-cli -R -W -P 4458 -k /root/tg2/tg-server.pub --json --permanent-peer-ids --permanent-peer-ids"
DEBUG:pytg.sender:Parsing raw: Argument help - <command> (needed)
DEBUG:pytg.sender:Sending command >[disable_preview] help
<
change_user_group: can't find the user telegramd to switch to
DEBUG:pytg.sender:Socket Connected.
DEBUG:pytg.sender:All Sent.
INFO:pytg:CLI available.
DEBUG:pytg.sender:Parsing send_msg: Argument miaow2 - <peer> (needed)
DEBUG:pytg.sender:Parsing send_msg: Argument /stock - <text> (needed)
DEBUG:pytg.sender:Sending command >[disable_preview] msg miaow2 '/stock'
<
DEBUG:pytg.sender:Socket Connected.
DEBUG:pytg.sender:All Sent.
Traceback (most recent call last):
File "/root/stock/tg12_stock.py", line 10, in <module>
sender.send_msg("miaow2", "/stock")
File "/usr/local/lib/python3.4/dist-packages/pytg/sender.py", line 630, in command_alias
return self.execute_function(command_name, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/pytg/sender.py", line 354, in execute_function
raise e
File "/usr/local/lib/python3.4/dist-packages/pytg/sender.py", line 351, in execute_function
return result_parser(message)
File "/usr/local/lib/python3.4/dist-packages/pytg/result_parser.py", line 55, in success_fail
raise FailException(json.error_code, json.error)
pytg.exceptions.FailException: Error 38: 'can not parse arg #1' (command "[disable_preview] msg miaow2 '/stock'\n")
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.
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python3.4/subprocess.py", line 960, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "/usr/lib/python3.4/subprocess.py", line 1602, in _communicate
input_view = memoryview(self._input)
TypeError: memoryview: str object does not have the buffer interface
read: Connection reset by peer
change_user_group: can't find the user telegramd to switch to: this is #81.
So the actual error is
pytg.exceptions.FailException: Error 38: 'can not parse arg #1' (command "[disable_preview] msg miaow2 '/stock'\n")
Strange, [disable_preview] should still work
is that problem solved? Because I m facing the same issue
@acanacar
Could you try the command manually in the CLI, and report back if that works?
In the log as DEBUG:pytg.sender:Sending command > <.
Also try with the CLI the same way as pytg does it,
See INFO:pytg:Starting Telegram Executable:
Tell me what works for you, if different to what pytg did. Also debug logs and your system configuration (uname -a, python --version) wouldn't hurt.
I've faced this problem and it seems to be from CLI, when you get the history from cli directly you get error: {"result": "FAIL", "error_code": 78, "error": "can not parse arg #1"}
But when you do a contact_list first and then get history it returns the history and now the script could be run it seems to a problem with the CLI
Same issue for me
Send dialog_list in telegram-cli, then start to use pytg should fix the problem. At least it works for me...