免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1823 | 回复: 0
打印 上一主题 下一主题

请教:python字典如何转换url编码 [复制链接]

论坛徽章:
2
狮子座
日期:2014-08-15 00:24:232015元宵节徽章
日期:2015-03-06 15:52:30
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-10-27 23:06 |只看该作者 |倒序浏览
本帖最后由 djzhangxing 于 2016-10-27 23:08 编辑
  1. In [1]: import urllib

  2. In [2]: urllib.quote('123')
  3. Out[2]: '123'

  4. In [3]: urllib.quote('你好')   
  5. Out[3]: '%E4%BD%A0%E5%A5%BD'

  6. In [4]: dic={"a":"123","b":"你好"}





  7. In [5]: urllib.quote(dic)   
  8. ---------------------------------------------------------------------------
  9. AttributeError                            Traceback (most recent call last)
  10. <ipython-input-5-d6d0b7327553> in <module>()
  11. ----> 1 urllib.quote(dic)

  12. /usr/local/lib/python2.7/urllib.pyc in quote(s, safe)
  13.    1299         safe = always_safe + safe
  14.    1300         _safe_quoters[cachekey] = (quoter, safe)
  15. -> 1301     if not s.rstrip(safe):
  16.    1302         return s
  17.    1303     return ''.join(map(quoter, s))

  18. AttributeError: 'dict' object has no attribute 'rstrip'



复制代码
字典格式该如何转换呢?

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP