gpt4 book ai didi

python - 使用 Python 请求库构建 URL

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

我有一个基本 URL。

BASE_URL = 'https://api.github.com/licenses'

我想根据附加到基本 URL 的搜索词(Ex - mit)创建一个新的 url。

NEW_URL = 'https://api.github.com/licenses/mit'

我正在使用请求库来构建和调用 URL,如下所示。

from requests.compat import urljoin

base_url = 'https://api.github.com/licenses'
new_url = urljoin(base_url, 'mit')
print new_url

但是当我打印 new_url 时,它弄乱了 URL。

https://api.github.com/mit

我不确定如何解决这个问题。

最佳答案

在基本 url 的末尾添加一个 /

BASE_URL = 'https://api.github.com/licenses/'

否则它可能会将许可证 视为文件名。

关于python - 使用 Python 请求库构建 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34830638/

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