使用python 2.7进行网址编码 [英] Url encode using python 2.7

查看:149
本文介绍了使用python 2.7进行网址编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>> import httplib
>>> x = httplib.HTTPConnection('localhost', 8080)
>>> x.connect()
>>> x.request('GET','/camera/store?fn=aaa&ts='+str.encode('2015-06-15T14:45:21.982600+00:00','ascii')+'&cam=ddd')
>>> y=x.getresponse()
>>> z=y.read()
>>> z

错误:格式无效:"2015-06-15T14:45:21.982600 00:00"格式错误,显示为"00:00""

'error: Invalid format: "2015-06-15T14:45:21.982600 00:00" is malformed at " 00:00"'

然后系统显示此错误.因为我想将此格式编码为:2015-06-15T14%3A45%3A21.982600%2B00%3A00

And the system show me this error. As i want to encode this format to this: 2015-06-15T14%3A45%3A21.982600%2B00%3A00

推荐答案

>>> import urllib
>>> f = { 'fn' : 'aaa', 'ts' : "2015-06-15T14:45:21.982600+00:00"}
>>> urllib.urlencode(f)

来自:

如何在Python中使用urlencode查询字符串?

这篇关于使用python 2.7进行网址编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆