簡體   English   中英

使用Python請求庫構建URL

[英]Build a URL using Python requests library

我有一個基本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/'

否則,它可能將許可證視為文件名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM