将字符串转换为 http 字符串格式

我需要发出 api 请求,我需要转换一个字符串,例如:


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

转换为请求格式,例如:


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

python 有一个库可以帮助我吗?


这是我的代码:


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)

谢谢


Smart猫小萌
浏览 126回答 1
1回答

拉莫斯之舞

您可以使用import urllib urllib.parse.quote_plus('string here')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python