为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Python中对查询字符串进行urlencode?

如何在Python中对查询字符串进行urlencode?

忽然笑 2019-07-19 14:39:05
如何在Python中对查询字符串进行urlencode?在提交之前,我正在尝试对此字符串进行urlencode。queryString = 'eventName=' + evt.fields["eventName"] + '&' + 'eventDescription=' + evt.fields["eventDescription"];
查看完整描述

3 回答

?
叮当猫咪

TA贡献1776条经验 获得超12个赞

你需要把你的参数传递给urlencode()作为映射(Dict)或二元组序列,如下所示:

>>> import urllib>>> f = { 'eventName' : 'myEvent', 'eventDescription' : 'cool event'}>>> urllib.urlencode(f)'eventName=myEvent&eventDescription=cool+event'

Python 3或以上

用途:

>>> urllib.parse.urlencode(f)eventName=myEvent&eventDescription=cool+event

请注意,这确实是在常用的意义上执行url编码(查看输出)。用于那种用途urllib.parse.quote_plus.


查看完整回答
反对 回复 2019-07-19
?
holdtom

TA贡献1805条经验 获得超10个赞

Python 2

你要找的是urllib.quote_plus:

>>> urllib.quote_plus('string_of_characters_like_these:$#@=?%^Q^$')'string_of_characters_like_these%3A%24%23%40%3D%3F%25%5EQ%5E%24'

Python 3

在Python 3中,urllib封装已被分解成较小的组件。你会用urllib.parse.quote_plus(注意parse儿童模块)

import urllib.parse
urllib.parse.quote_plus(...)


查看完整回答
反对 回复 2019-07-19
  • 3 回答
  • 0 关注
  • 2089 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信