urllib2无法处理url中的冒号 [英] urllib2 having trouble processing colon symbol in url

查看:135
本文介绍了urllib2无法处理url中的冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用API​​进行挑战,其网址格式为 https://username:password @ challonge .com/api/但是,当在python中使用urllib2来获取此URL时,response = urllib2.urlopen('https://username:password@challonge.com/api/'),我得到了一个错误关于非数字端口号.我相信这是由URL中的冒号(:)引起的,使得urllib2认为我正在尝试获取某些端口.无论如何都存在这个问题,还是我做错了什么?

I am using the API for challonge and their url format is https://username:password@challonge.com/api/ However, when the use urllib2 in python to get this url, response = urllib2.urlopen('https://username:password@challonge.com/api/'), I get an error about a non-numerical port number. I believe this is cause by the colon (:) in the url making urllib2 think i'm trying to get a port of something. Is there anyway around this issue, or am I doing something wrong?

推荐答案

这是因为您必须使用urllib2.HTTPBasicAuthHandler之类的身份验证处理程序. urllib2文档

This is because you must use auth handlers like urllib2.HTTPBasicAuthHandler or other. urllib2 docs

这篇关于urllib2无法处理url中的冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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