0

i need to make and api request and i need to convert a strin like:

"hello i am a special string + i contain special characters?"

into a request format like:

"hello%20i%20am%20a%20special ... ecc"

does python has a library to help me out?

this is my code:

import http.client
conn = http.client.HTTPSConnection("address:port")
conn.request(method="GET", url="/my/target/site?info1=this needs to be converted&info2=also this???", headers=headers)

thanks

4
  • Are you only trying to remove spaces? Commented Aug 15, 2020 at 23:57
  • @jon I think if there are special characters like =, >, it should also be converted Commented Aug 15, 2020 at 23:59
  • 1
    is that what you are looking for? stackoverflow.com/questions/5607551/… Commented Aug 15, 2020 at 23:59
  • @Hedy my idea is that you do split() and then join() function for each special character that you want to endcode but ink how effecient is that Commented Aug 16, 2020 at 0:01

1 Answer 1

2

Like in How to convert a url string to safe characters with python? And How to urlencode a querystring in Python?

You can use

import urllib
urllib.parse.quote_plus('string here')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.