对字符串传入的字典参数进行urlencode编码,就需要用到两个方法urlencode和quote
urlencode方法传字典参数

from urllib.parse import urlencode, quote, unquote

# urlencode方法参数是字典

body = {
    "content": "呃呃呃",
    "charsetSelect": "utf-8",
    "en": "UrlEncode编码"
}
print(urlencode(body))

quote传字符串参数

# quote方法参数是字符串

print(quote("上海-悠悠"))

url = "http://www.example.com/?a=问问为&b=同人文"
print(quote(url))
======================================================
import requests
from urllib.parse import urlencode, quote, unquote

url = "http://www.example.com/"
par = {
    "a": "问问",
    "b": "嗯嗯"
}
body = {
    "content": "嗯嗯",
    "charsetSelect": "utf-8",
    "en": "UrlEncode编码"
}

r = requests.post(url, params=par, data=body)
print(r.url)
print(unquote(r.url))

 

 
 

相关文章:

  • 2022-12-23
  • 2021-12-24
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2021-08-31
  • 2021-10-30
猜你喜欢
  • 2021-07-29
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案