python - 将字符串转换为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)
谢谢
解决方案
就像如何使用 python 将 url 字符串转换为安全字符? 以及 如何在 Python 中对查询字符串进行 urlencode?
您可以使用
import urllib
urllib.parse.quote_plus('string here')
推荐阅读
- c# - 如何向 ImageCropper 工具包添加旋转:UWP
- sql - 在 SQL 中将一行拆分为多行,金额均分
- python - 如何遍历熊猫数据框行,查找字符串并分成列?
- merge - 合并分支 - 合并太大而无法显示,但只更改了一个文件?
- javascript - 具有同步导航的滑块
- c++ - 课堂上的&字符是什么意思?
- java - Vaadin 8:如何从另一个线程更新模态表单上的标签值
- python - 来自 Cloud Function 的 Google Anaytics Reporting API 和 Google Managed Key
- java - 如何使用 Maven 将 JavaFX 项目部署到 EXE?
- google-api - 谷歌如何“理解”我已经登录谷歌服务(如 gmail)