Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a URL using Python requests library

I have a base URL.

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

I want to create a new url based on a search term(Ex - mit) appended to the base URL.

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

I am using requests library to build and call the URLs as shown below.

from requests.compat import urljoin

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

But when I print the new_url, it messes up the URL.

https://api.github.com/mit

I am not sure how to fix this issue.

like image 326
Pattu Avatar asked Sep 26 '22 16:09

Pattu


1 Answers

Add a / at the end of the base url.

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

Otherwise it's probably treating licences as filename.

like image 108
jatinderjit Avatar answered Oct 03 '22 07:10

jatinderjit