pytg icon indicating copy to clipboard operation
pytg copied to clipboard

Error in function msg: parameter #1 <text> is not type UnicodeString

Open mohamadiank opened this issue 7 years ago • 4 comments

The problem

i've download command_send_message.py from example directory and run it by python. but return me this eror: ValueError: Error in function msg: parameter #1 <text> is not type UnicodeString. (Not a string.)

mohamadiank avatar Mar 13 '17 02:03 mohamadiank

I guess your input is no unicode string. So I assume python 2?

luckydonald avatar Mar 13 '17 17:03 luckydonald

my trace:

Traceback (most recent call last):
  File "command_send_message.py", line 13, in <module>
    sender.msg("@ehsankhorasani", "text")
  File "/home/fatman/w/pytg/.env/local/lib/python2.7/site-packages/pytg/sender.py", line 630, in command_alias
    return self.execute_function(command_name, *args, **kwargs)
  File "/home/fatman/w/pytg/.env/local/lib/python2.7/site-packages/pytg/sender.py", line 274, in execute_function
    command_name, new_args = self._validate_input(function_name, arguments)
  File "/home/fatman/w/pytg/.env/local/lib/python2.7/site-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.)

Edited by @luckydonald: Syntax highlighting

mohamadiank avatar Mar 14 '17 02:03 mohamadiank

@ehsankhorasani you must decode your text and username to send it via pytg convert something like this sender.send_msg("@somebody", "Hello World!") to this sender.send_msg("@somebody".decode("utf-8"), "Hello World!".decode("utf-8"))

EDIT: according to @luckydonald better way is this : sender.send_msg(u"@somebody", u"Hello World!")

shotgunner avatar Jun 18 '17 20:06 shotgunner

@shotgunner's comment applies to python 2. Python 3 works out of the box.

Actually

sender.send_msg(u"@somebody", u"Hello World!")

is possible too.

luckydonald avatar Jun 20 '17 19:06 luckydonald