开发者

python uni-code server error while passing non English words

I build a customized search web page using some other search engine. like.

For client side am encode the search terms and send to the 开发者_StackOverflowmy server using

http://xxx.appspot.com/search?q=encodeUIComponent(qTerms)

At server side(appengine - python) am decoding the text using urllib

like qTerms= urllib.unquote_plus(qTerms)

and again i encoded the sterms. using qTerms= urllib.quote_plus(qTerms)

now i send qTermsto the another server from my server and i get xml response.

Above designs works well for pure engilsh words when i pass the non english words its givin error like below:

Traceback (most recent call last): 
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py",          line 701, in __call__
    handler.get(*groups)
  File "/base/data/home/apps/s~searchepic/1.353951740301902288/search.py", line 124, in get
    qTerms = urllib.quote_plus(qTerms)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib.py", line 1222, in quote_plus
    return quote(s, safe)
  File "/base/python_runtime/python_dist/lib/python2.5/urllib.py", line 1214, in quote
    res = map(safe_map.__getitem__, s)
KeyError: u'\u0c15' 


You need to pass quote() ASCII (str) string instead of unicode string.
You porbbley need to call term.encode('utf8') and pass the result to quote()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜