5

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.

1 Answer 1

4

Add a / at the end of the base url.

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

Otherwise it's probably treating licences as filename.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.