我无法弄清楚如何验证登录github以获取XML或JSON数据。这是我现在的代码:
import urllib2, sys, re, base64
url = "https://api.github.com/user"
username = "username"
password = "password"
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
pagehandle = urllib2.urlopen(url).read()
我一直在修补我发现的这段代码,但我似乎总是收到一条错误,指出“urllib2.HTTPError:HTTP错误401:未经授权。”
我很肯定我的登录信息是正确的,我不明白为什么我收到此错误。