Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11631

How to url encode special character ~ in Python?

$
0
0

I am trying to do an url encoding on the following string the following string 'https://bla/ble:bli~' using the urllib standard library on Python 3.10. Problem is that the ~ character is not encoded to %7E as perurl encoding. Is there a way around it?

I have tried

from urllib.parse import quoteinput_string = 'https://bla/ble:bli~'url_encoded = quote(input_string)

url_encoded takes the value 'https%3A//bla/ble%3Abli~'

I have also tried:

url_encoded = quote(input_string,safe='~')

In this case the url_encoded takes the value 'https%3A%2F%2Fbla%2Fble%3Abli~'


Viewing all articles
Browse latest Browse all 11631

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>