python urllib2 basic authentication
问题 Hi i'm trying to use python to access an API URL using urllib2: import urllib2 url = 'https://XXXXXXXXXX.com/' username = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' 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) I don't know what the