gpt4 book ai didi

python-3.x - python3请求使用quote而不是quote_plus

转载 作者:行者123 更新时间:2023-12-03 09:33:31 25 4
gpt4 key购买 nike

我使用 Python 3 和 requests用于查询 REST 服务的模块/库。

似乎请求默认使用 urllib.parse.quote_plus()对于 urlencoding,即空格转换为 + .

但是,我查询的 REST 服务将其误解为 and .所以我需要将空格编码为 %20 ,即使用 urllib.parse.quote()反而。

有没有简单的方法来处理请求?我在文档中找不到任何选项。

最佳答案

事实证明你可以!

from requests.utils import requote_uri
url = "https://www.somerandom.com/?name=Something Cool"
requote_uri(url)

'https://www.somerandom.com/?name=Something%20Cool'

documentation here requote_uri方法大约在页面的一半。

关于python-3.x - python3请求使用quote而不是quote_plus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42349000/

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