twintproject / twint

An advanced Twitter scraping & OSINT tool written in Python that doesn't use Twitter's API, allowing you to scrape a user's followers, following, Tweets and more while evading most API limitations.
MIT License
15.75k stars 2.72k forks source link

[BUG] UnicodeEncodeError in Idle with fix #152

Closed cbjrobertson closed 6 years ago

cbjrobertson commented 6 years ago

Note

Sorry for the cross post, I'm still new to git:) I've implemented the suggestion below in PU #153.

Command Ran

import twint

c = twint.Config()
c.Store_csv = True
c.Output = '../path/to/sheet.csv'
c.Since = '2017-06-16'
c.Until = '2017-06-25'
c.Search = """canneslions OR cannes OR platformforaction OR
                OR googlebeach OR cannes2017 OR canneslions2017 OR
               agencylife OR google"""
c.Lang ='en'
c.Format = '''id: {id} | date: {date} | time: {time} | user_id: {user_id} | username: {username} |
              tweet: {tweet} | timezone: {timezone} | hashtags: {hashtags} 
              replies: {replies} | retweets: {retweets} | likes: {likes}'''

twint.run.Search(c)

Description of Issue

The above code produces a UnicodeEncodeError relating to printing in Idle, see this. Traceback below:

Traceback (most recent call last):
  File "/path/to/my/script.py", line 21, in <module>
    twint.run.Search(c)
  File "/anaconda3/envs/twitter_scrape/lib/python3.6/site-packages/twint/run.py", line 25, in Search
    run(search.Search(config).main())
  File "/anaconda3/envs/twitter_scrape/lib/python3.6/site-packages/twint/run.py", line 5, in run
    get_event_loop().run_until_complete(x)
  File "/anaconda3/envs/twitter_scrape/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
    return future.result()
  File "/anaconda3/envs/twitter_scrape/lib/python3.6/site-packages/twint/search.py", line 49, in main
    await self.tweets()
  File "/anaconda3/envs/twitter_scrape/lib/python3.6/site-packages/twint/search.py", line 37, in tweets
    await output.Tweets(tweet, "", self.config, self.conn)
  File "/anaconda3/envs/twitter_scrape/lib/python3.6/site-packages/twint/output.py", line 59, in Tweets
    _output(tweet, output, config)
  File "/anaconda3/envs/twitter_scrape/lib/python3.6/site-packages/twint/output.py", line 45, in _output
    print(output)
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 389-389: Non-BMP character not supported in Tk

Environment Details

Using OSX 10.13.3, twint 1.1.3.4, running using Idle with python 3.6.5

Fix

To fix this, I changed line 45 in output.py from:

print(output)

to:

try:
    print(output)
except UnicodeEncodeError:
    pass
haccer commented 6 years ago

Thanks for the pull request!

cbjrobertson commented 6 years ago

no problem:)

C

Cole

On Fri, Jun 15, 2018 at 8:54 PM, Cody Zacharias notifications@github.com wrote:

Thanks for the pull request!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/twintproject/twint/issues/152#issuecomment-397725958, or mute the thread https://github.com/notifications/unsubscribe-auth/AVVeHk-zShEIGBIZNy3ycCADZJu8bbkSks5t9BD8gaJpZM4UpWzj .