带有æøå的Python urllib urlencode问题 [英] Python urllib urlencode problem with æøå

查看:158
本文介绍了带有æøå的Python urllib urlencode问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用特殊字符æøåurlencode一个字符串?

How can I urlencode a string with special chars æøå?

例如.

urllib.urlencode('http://www.test.com/q=testæøå')

我收到此错误:(..

I get this error :(..

不是有效的非字符串序列,或者 映射对象

not a valid non-string sequence or mapping object

推荐答案

您应该将字典传递给urlencode,而不是字符串.请参见下面的正确示例:

You should pass dictionary to urlencode, not a string. See the correct example below:

from urllib import urlencode
print 'http://www.test.com/?' + urlencode({'q': 'testæøå'})

这篇关于带有æøå的Python urllib urlencode问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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