Reputation: 646
I am trying to join these two URIs
from urllib.parse import urljoin
# baskslash is not a mistake
r = urljoin(r"https:/\\corrlinks.blob.core.windows.net", r"videofaq")
print(r)
I am getting
https:///videofaq
How can I get
https:/\\corrlinks.blob.core.windows.net/videofaq
This one would be Ok too:
https://corrlinks.blob.core.windows.net/videofaq
Note. Browsers handle the link above just fine.
Upvotes: 0
Views: 154
Reputation: 646
I have ended up with
url = url.replace("\\" , "/").replace("///", "//")
Upvotes: 0
Reputation: 1620
Function interpret slash as baseurl, so you're need to add another one at the end to teach it:
urljoin(r"https:/\\corrlinks.blob.core.windows.net/", "videofaq")
Upvotes: 1
Reputation: 40
python treats backslash(\) as an escape character.
using r'string' goes handy many times.
r just means raw string. This is useful when we want to have a string that contains backslash and don’t want it to be treated as an escape character.
In this case
from urllib.parse import urljoin
r = urljoin(r"https://corrlinks.blob.core.windows.net", "videofaq")
print(r)
# returns https://corrlinks.blob.core.windows.net/videofaq
This should do the work.
Upvotes: 0