Skip to content

Instantly share code, notes, and snippets.

Last active July 31, 2017 14:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save IvanTurgenev/5f1bc5513ca76afdf6d594a6f0b4914c to your computer and use it in GitHub Desktop.
Line 45 ERROR UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 16: ordinal not in range(128), has something to do with add
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib64/python2.7/", line 804, in __bootstrap_inner
File "/usr/lib64/python2.7/", line 757, in run
self.__target(*self.__args, **self.__kwargs)
File "", line 48, in poststream # GIST HAS DIFFERENT NUMBER OF LINES
File "/home/kenmr/.local/lib/python2.7/site-packages/praw/models/reddit/", line 1362, in add, data=data)
File "/home/kenmr/.local/lib/python2.7/site-packages/praw/", line 432, in post
return self._objector.objectify(data)
File "/home/kenmr/.local/lib/python2.7/site-packages/praw/", line 122, in objectify
raise APIException(*errors[0])
File "/home/kenmr/.local/lib/python2.7/site-packages/praw/", line 25, in __init__
error_str = '{}: \'{}\''.format(error_type, message)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 16: ordinal not in range(128)
import praw
import re
import collections
import threading
reddit = praw.Reddit(client_id='XXXXX', client_secret="XXX",
password='X', user_agent='BOT',
subredditra = reddit.subreddit("subreddit to get contributors list with mod permission")
contlist = []
for contributor in subredditra.contributor(limit=None):
wanted = ["wanted","words","in","comments","to","add","to","contributors"]
def commstream(subreddit):
sub = reddit.subreddit(subreddit)
for comment in
text = comment.body # Fetch body
author =
# print author
cnt = collections.Counter()
words = re.findall('\w+', text.lower())
for word in words:
if word in wanted:
cnt[word] += 1
cntsum = (sum(cnt.values()))
if (not author in contlist) and (len (cnt) >= 2) :#and ((len cnt) >= 2):
print author
print text
print cntsum
print cnt
def poststream(subreddit):
sub = reddit.subreddit(subreddit)
for submission in
author =
title = submission.title
if (not author in contlist):
print title
print author
subredditra.contributor.add(author) #ERROR
# qcp = Queue.Queue()
# qpc = Queue.Queue()
thread1 = threading.Thread(target=commstream,args=["subreddit to stream comments"])
thread2 = threading.Thread(target=poststream,args=["subreddit to stream post"])
# while True:
# try:
# commstream()
# except praw.errors.HTTPException as error:
# if error._raw.status_code == 503:
# time.sleep(30)
# print("503 ERROR")
# continue
# else:
# raise SystemExit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment