0

urljoin corrupts the data

from urllib.parse import urljoin
base = "https://dummy.restapiexample.com/api/v1"
tail = "/employees"
urljoin(base, tail)

returns

'https://dummy.restapiexample.com/employees'

eating "/api/v1".

Dims
  • 47,675
  • 117
  • 331
  • 600

1 Answers1

-1

base and tail are strings. ''.join([base, tail]) is one such way to join these strings:

>>> base = "https://dummy.restapiexample.com/api/v1"
>>> tail = "/employees"
>>> ''.join([base, tail])
'https://dummy.restapiexample.com/api/v1/employees'

Strings have a join method, which takes in a list of strings and returns a concatenated string from said list, with copies of the calling string separating the substrings which are copies of the strings in the list -- so, for example, '/'.join(['a','s','d','f']) returns 'a/s/d/f'. If '' calls this method, it simply returns the list concatenated into one string.