gpt4 book ai didi

python - RFC 3986 的 urlencode()

转载 作者:太空狗 更新时间:2023-10-30 02:46:24 28 4
gpt4 key购买 nike

Python 有一个很棒的 urlencode()通过 RFC 1738(Plus 编码)对 dict 进行编码的函数:

>>> urllib.parse.urlencode({'site':'Stack Overflow','Coder':'Jeff Atwood'})
'Coder=Jeff+Atwood&site=Stack+Overflow'

我找不到使用 RFC 3986(百分比编码)的替代品,即使手册很好 states the following :

RFC 3986 - Uniform Resource Identifiers
This is the current standard (STD66). Any changes to urllib.parse module should conform to this.

这将是预期的输出:

>>> urllib.parse.urlencode({'site':'Stack Overflow','Coder':'Jeff Atwood'})
'Coder=Jeff%20Atwood&site=Stack%20Overflow'

当然我可以自己动手,但令我惊讶的是我找不到内置的 Python 函数。有没有这样的 Python 函数我只是找不到?

最佳答案

似乎没有内置这样的东西,但是有一个错误要求一个,它甚至还附带了一个补丁:http://bugs.python.org/issue13866

关于python - RFC 3986 的 urlencode(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20801929/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com