UNI code URL连接code /德code与Python [英] Unicode URL encode / decode with Python
问题描述
我有一个Android应用程序,它使用
URLEn coder.en code(S.getSongArtist(),UTF-8)
为en code被发布到AppEngine上的Python(2.7)Web服务的单向code字符串。在服务我用
urllib.unquote_plus(艺术家)
这是不是给我正确的结果。我有这样一个输入:
玛丽+ Lafor%C3%AAT
这是unquote'd到
玛丽Laforêt
如果我使用JavaScript网址去code,例如: HTTP: //meyerweb.com/eric/tools/den$c$cr/
我得到
玛丽Laforêt美景
有一个正确的结果。
我试图用
urllib.unquote(艺术家)由Matchi.com提供回到code(UTF-8)
,但这会产生一个异常。在所有的任何提示都大大AP preciated。
修改
Taxellool曾在评论中正确的答案:
您正试图去code是什么已经去codeD。试试这个:
urllib.unquote_plus(artist.en code(UTF-8))。德code(UTF-8)
Taxellool曾在评论中正确的答案:
您正试图去code是什么已经去codeD。试试这个:
urllib.unquote_plus(artist.en code(UTF-8))。德code(UTF-8)
I have an Android app which uses
URLEncoder.encode(S.getSongArtist(),"UTF-8")
to encode a unicode string that is posted to a AppEngine python (2.7) web service. On the service I use
urllib.unquote_plus(artist)
This is not giving me correct results. I have an input like this:
Marie+Lafor%C3%AAt
which is unquote'd to
Marie Laforêt
If I use a javascript url decode, for instance: http://meyerweb.com/eric/tools/dencoder/ I get
Marie Laforêt
A correct result.
I tried using
urllib.unquote(artist).decode('utf-8')
but this generates an exception. Any hints at all are greatly appreciated.
EDIT
Taxellool had the right answer in the comments:
what you are trying to decode is already decoded. try this:
urllib.unquote_plus(artist.encode('utf-8')).decode('utf-8')
Taxellool had the right answer in the comments:
what you are trying to decode is already decoded. try this:
urllib.unquote_plus(artist.encode('utf-8')).decode('utf-8')
这篇关于UNI code URL连接code /德code与Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!