我有表单的自定义url
http://somekey:somemorekey@host.com/getthisfile.json
我试了一路,但还是出错了:
方法1:
from httplib2 import Http
ipdb> from urllib import urlencode
h=Http()
ipdb> resp, content = h.request("3b8138fedf8:1d697a75c7e50@abc.myshopify.com/admin/shop.json")
错误:
^{pr2}$方法2: 导入urllib
urllib.urlopen(url).read()
错误:
*** IOError: [Errno url error] unknown url type: '3b8108519e5378'
我猜编码有问题。。在
我试过。。。在
ipdb> url.encode('idna')
*** UnicodeError: label empty or too long
有没有什么方法可以让这个复杂的url得到轻松的调用。在
您使用的是基于PDB的调试器,而不是交互式Python提示符。
h
是PDB中的一个命令。使用!
可防止PDB试图将该行解释为命令:
^{pr2}$urllib
要求您向它传递一个完全限定的URL;您的URL缺少一个方案:您的URL在域名中似乎没有使用任何国际字符,因此不需要使用IDNA编码。
您可能需要了解第三方^{} library ;它使与HTTP服务器的交互变得更加简单明了:
Python当前实际的HTTP库是Requests。
相关问题 更多 >
编程相关推荐