python - 如何在 Python 中将字典转换为查询字符串?

标签 python urllib2 urllib

使用cgi.parse_qs()后,如何将结果(字典)转换回查询字符串?寻找类似于 urllib.urlencode() 的东西。

最佳答案

Python 3

urllib.parse.urlencode(query, doseq=False, [...])

Convert a mapping object or a sequence of two-element tuples, which may contain str or bytes objects, to a percent-encoded ASCII text string.

Python 3 urllib.parse docs

dict 是一个映射。

旧版 Python

urllib.urlencode(query[, doseq])
Convert a mapping object or a sequence of two-element tuples to a “percent-encoded” string... a series of key=value pairs separated by '&' characters...

Python 2.7 urllib docs

关于python - 如何在 Python 中将字典转换为查询字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7801991/

相关文章:

python - 未知的 Python 错误

python - 如何在 url 列表中快速找到不返回 302(重定向)状态代码的最后一个可用 url

Python urllib POST 响应

python 3 : Move email to trash by uid (imaplib)

python - 在这种情况下如何在 python 中重置单例实例?

ssl - 通过代理的 PKI 身份验证,python 2.6.6

python - 使用 Python/urllib2 处理 rss 重定向

python - 使用 urlretrieve 后关闭 ftp 连接

Python 3-如何使用 TKINTER 从 Web 检索图像并在 GUI 中显示?

python - 如何打乱列表中的顺序?