Was ist das Äquivalent von urllib.parse.quote
Equivalent urllib.parse.quote() in Python 2.7
Es ist urllib.urlencode()
?
Danke
Was ist das Äquivalent von urllib.parse.quote
Equivalent urllib.parse.quote() in Python 2.7
Es ist urllib.urlencode()
?
Danke
Ich glaube, Sie für urllib.pathname2url suchen. Vergleichen:
Python 3, urllib.parse.quote:
>>> urllib.parse.quote('abc def/foo?bar=baz')
'abc%20def/foo%3Fbar%3Dbaz'
Python 2, urllib.pathname2url:
>>> urllib.pathname2url('abc def/foo?bar=baz')
'abc%20def/foo%3Fbar%3Dbaz'
Das Verhalten scheint ähnlich wie mir, aber sie könnten auf subtile Weise anders sein.
Edit:
Lesen Sie Ihre Anmerkung an Algina der Post, ich denke, das ist meine bevorzugte Art und Weise ist es, die URL zu erstellen:
>>> url = 'http://dev.echonest.com/api/v4/song/search'
>>> params = {'api_key': 'xxxx', 'format': 'json', 'artist': 'Galaxie 500'}
>>> "{}?{}".format(url, urllib.urlencode(params))
'http://dev.echonest.com/api/v4/song/search?api_key=xxxx&artist=Galaxie+500&format=json'
Können Sie genauer? Sie haben urllib.parse.quote_plus(...) urllib.parse.quote_from_bytes(...) urllib.parse.unquote(...)
wie Sie
siehe doc hier erwähnt: https://docs.python.org/3.2/library/urllib.parse.html
Danke, Ich habe 'req = 'http://dev.echonest.com/api/v4/song/search?api_key=xxxx&format=json&artist=' + urllib.parse.quote (Künstler)' Und 'artist =" Oasis "' – timothylhuillier
tatsächlich die Bibliothek mit six
, die für python2 gemacht wird/python3 Kompatibilität können Sie
import six.moves.urllib as urllib
# and now you can use urllib as it was python3
urllib.quote(...)
tun, und wenn Sie nur python2 wollen, war es eigentlich urllib.quote
di rekt
Vielen Dank für diesen Tipp! –
Hi @ allan.simon, ich habe das Paket 'six (1.10.0)' installiert und erhalte 'AttributeError: 'Das Objekt' Module_six_moves_urllib 'hat kein Attribut' quote' ... Irgendeine Idee warum? –
Scheint, ich brauchte 'urllib.parse.quote (...)' (eigentlich in meinem Fall brauchte ich 'urllib.parse.quote_plus (...)'). –
Danke, ich werde das versuchen – timothylhuillier