pytg
pytg copied to clipboard
msg: parameter #1 <text> is not type UnicodeString.
Just installed this package, get my telegram-cli running by
/bin/telegram-cli --json -W -d -P 4458
And when i run this example: https://github.com/luckydonald/pytg/blob/master/examples/command_send_message.py I got this: (i changed only my username)
Traceback (most recent call last):
File "command_send_message.py", line 19, in <module>
main()
File "command_send_message.py", line 14, in main
res = sender.msg("@timhok", "Hello!")
File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 630, in command_alias
return self.execute_function(command_name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pytg/sender.py", line 274, 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 414, 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 msg: parameter #1 <text> is not type UnicodeString. (Not a string.)
I also tried unicode strings with no success:
pytg.exceptions.FailException: Error 38: u'can not parse arg #1' (command u"[disable_preview] msg timhok 'Hello'\n")
I realize that maybe pytg sends msg command without "@" symbol in name, and last version of telegram-cli (version 1.4.1, tgl version 2.1.0) does not support that:
timhok@srv04:~# echo msg timhok hi | nc 127.0.0.1 4458
ANSWER 70
{"result": "FAIL", "error_code": 38, "error": "can not parse arg #1"}
^C
timhok@srv04:~# echo msg @timhok hi | nc 127.0.0.1 4458
ANSWER 22
{"result": "SUCCESS"}
^C
FYI: pytg usually starts the CLI with this arguments. Does that json output differ?
Hey, I have the exact same problem, tried the arguments, which doesn't help. Anything else?
You have to decode the text before sending as it expects unicode text:
res = sender.msg("@nick", "hi".decode("utf-8"))
will make it
What is your python version? 2.7?
Yes in that example I used the 2.7
You can probably also use u"hi"
insead of "hi".decode(...)
using u"msg'
or "msg".decode("utf-8")
fixed the error for me,
but now I get # TODO remove me NoResponse: [disable_preview] msg @contact 'msg :)'
Update:
ok, I started telegram-cli
manually with --json -P 4458
and it fixed my problem.
Sorry, you didn't write with version of python on what OS you are running.
If using Python 2, be sure you are using Unicode strings (unicode
), not the normal (binary) str
.
Or just use Python 3.
I'm Using Ubuntu 16.04 LTS
And Python 2.7
I'm getting the same error with python 3.5.2
on Linux-4.4.0-75-generic-x86_64-with-Ubuntu-16.04-xenial
,
Traceback (most recent call last):
File "cli.py", line 5, in <module>
res = sender.send_msg('@bitwisepi', u"Testing, does this thing work?")
File "/usr/local/lib/python3.5/dist-packages/pytg/sender.py", line 630, in command_alias
return self.execute_function(command_name, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pytg/sender.py", line 354, in execute_function
raise e
File "/usr/local/lib/python3.5/dist-packages/pytg/sender.py", line 351, in execute_function
return result_parser(message)
File "/usr/local/lib/python3.5/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 @bitwisepi 'Testing, does this thing work?'\n")
Tried passing both arguments as unicode strings, still throws an error.
Which cli version (The commit hash?) are you using?
Should be 6547c0b21b977b327b3c5e8142963f4bc246187a
, the most recent one
I actually fixed this error by adding quotes before and after the peer value in my msg() function, but it still returns the same error as described in #81, with the "can't find user telegramd to switch to" value