传递非英语单词时python unicode服务器错误
我使用其他一些搜索引擎构建了一个定制的搜索网页。喜欢。
对于客户端,我对搜索词进行编码,并使用 http://xxx 发送到我的服务器
。 appspot.com/search?q=encodeUIComponent(qTerms)
在服务器端(appengine - python)使用 urllib 解码文本,
如 qTerms= urllib.unquote_plus(qTerms)
并再次对词干进行编码。 使用 qTerms= urllib.quote_plus(qTerms)
现在我将 qTerms 从我的服务器发送到另一台服务器,并收到 xml 响应。
当我传递非英语单词时,上面的设计非常适合纯英语单词,其给出的错误如下:
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'
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 my 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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要传递 quote() ASCII (str) 字符串而不是 unicode 字符串。
您可能需要调用
term.encode('utf8')
并将结果传递给 quote()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()