如何在Python 3中进行URL编码?

问题描述 投票:30回答:3

我曾尝试关注the documentation,但无法在urlparse.parse.quote_plus()中使用Python 3

from urllib.parse import urlparse

params = urlparse.parse.quote_plus({'username': 'administrator', 'password': 'xyz'})

我知道

AttributeError:'function'对象没有属性'parse'

python urlencode
3个回答
49
投票

您误读了文档。您需要做两件事:


13
投票

对于Python 3,您可以尝试使用quote而不是quote_plus


4
投票

您正在寻找urllib.parse.urlencode

© www.soinside.com 2019 - 2024. All rights reserved.