Instapy: Emoji

Created on 16 Apr 2017  Â·  10Comments  Â·  Source: timgrossmann/InstaPy

Hi,

On my MacBook the script won’t start when there are Emoji in the comments section. I’m only using those Emoji mentioned in unicode.md and the same script works on other machines very well.

When I declare the script as utf8 (# coding: utf8) the script starts at least but crashes when the comment is being inserted the first time:

response = self.command_executor.execute(driver_command, params)
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/remote_connection.py", line 398, in execute
    data = utils.dump_json(params)
  File "/Library/Python/2.7/site-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/remote/utils.py", line 34, in dump_json
    return json.dumps(json_struct)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe2 in position 0: unexpected end of data

This is what my script looks like:

# coding: utf8
from instapy import InstaPy

#Write your automation here
#Stuck ? Look at the github page or the examples in the examples folder

InstaPy(username='MyUserName',password='MyPassword')\
  .login()\
  .set_do_comment(True,percentage=25)\
  .set_comments(['Super ✌ #fb','Nice! #fb','☀ Great Shot ✌ #fb','✌✌✌ #fb','✊ #fb','✊✊✊ #fb','Nice #fb','Nice 1 #fb','Great #fb','Awesome ✌ #fb','Cool'])\
  .set_do_follow(enabled=True,percentage=10,times=2)\
  .like_by_tags(['#architecture','#bw','#color','#colors','#followback','#follow4follow','#road','#colors','#color'],amount=5000)\
.end()

Has anyone an idea what could be the reason for this behaviour? The same script works on other machines without any problem…

Most helpful comment

@pekapa I see the problem. The second value isn't the 4 letter set.

https://github.com/timgrossmann/InstaPy/issues/2

All 10 comments

It's not InstaPy related.

Why you don't use the unicodes code instead?
https://en.wikipedia.org/wiki/Emoji

@tibor This won't work this way...

You have to do it with the unicode characters like @vlntdds mentioned.

e.g.
```
u'That is cool! u270A'

Right now, it won't work any other way...

So @timgrossmann I am on my macbook as well and I tried putting in the unicode characters like the example above ('u270A') and the script echoes that exact string (no emoji) to the comment. How do I make it render the emoji?

@knofun works fine for me 💯

I'm using Python 3.6.1 on Windows

@knofun
Try marking it as unicode, see if it works.
(u'\u270A')

That worked, thanks!

@pekapa I'm having problems using multi emojis and also using text in the string. Have you ever tried something similar?

I don't use the comment function at all, just the bare basics of linking.

But you should be able to use it just the same way, mark it as unicode.
Something like this:
u'That is cool! \u270A'

@pekapa That works fine for 1 comment value, but when I try and use

session.set_comments([u'That is cool! \u270A', u'That is cool! \u1F918'])

The second comment is not encoded correctly and the emoji isn't formatted correctly.

@pekapa I see the problem. The second value isn't the 4 letter set.

https://github.com/timgrossmann/InstaPy/issues/2

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Spyd3r0us picture Spyd3r0us  Â·  3Comments

CodeMaster1 picture CodeMaster1  Â·  3Comments

46960 picture 46960  Â·  3Comments

drcyber975 picture drcyber975  Â·  3Comments

CharlesCCC picture CharlesCCC  Â·  3Comments