Using Urlencode For Devanagari Text
The following code: import simplejson,urllib,urllib2 query=[u'नेपाल'] urlbase='http://search.twitter.com/search.json' values={'q':query[0]} data=urllib.urlencode(val
Solution 1:
You need to add the UTF-8 header to your file to tell the Python interpreter that there are unicode literals. You also have to encode the parameters as UTF-8. Here's a working version:
# -*- coding: utf-8 -*-
import simplejson,urllib,urllib2
query=[u'नेपाल']
urlbase="http://search.twitter.com/search.json"
values={'q':query[0].encode('utf-8')}
data=urllib.urlencode(values)
req=urllib2.Request(urlbase,data)
response=urllib2.urlopen(req)
json=simplejson.load(response)
print json
Post a Comment for "Using Urlencode For Devanagari Text"