From 52447f3f81f5ba9aadad5cdb565eefe4149a8444 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 11 Oct 2010 10:16:46 +0100 Subject: [PATCH] Handle UTF8/Unicode in the Reddit API This fixes Ps3udo's issues with his welcome text --- reddit/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reddit/api.py b/reddit/api.py index ef08b77..4985605 100644 --- a/reddit/api.py +++ b/reddit/api.py @@ -2,6 +2,7 @@ import simplejson as json import urllib2 import urllib from datetime import datetime +import unicodedata class NotLoggedIn(Exception): pass @@ -106,7 +107,7 @@ class Inbox(): self._opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) urllib2.install_opener(self._opener) - req = urllib2.Request( url, urllib.urlencode(data)) + req = urllib2.Request(url, urllib.urlencode(data)) return self._opener.open(req) def __len__(self): @@ -123,8 +124,8 @@ class Inbox(): raise NotLoggedIn data = { 'to': to, - 'subject': subject, - 'text': text, + 'subject': subject.encode('utf-8'), + 'text': text.encode('utf-8'), 'uh': self.modhash, 'thing_id': '' } url = "%s" % (self.REDDIT_API_COMPOSE)