如何解决将字符串转换为http字符串格式
我需要发出和api请求,并且需要转换一个strin像这样:
"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)
谢谢
解决方法
像How to convert a url string to safe characters with python? 还有How to urlencode a querystring in Python?
您可以使用
import urllib
urllib.parse.quote_plus('string here')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。