python - Check GitHub credentials validity -
i trying verify github credentials python.
i have tried this:
import urllib2, base64 username = "test@example.com" password = "password" request = urllib2.request("https://github.com/") base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') request.add_header("authorization", "basic %s" % base64string) result = urllib2.urlopen(request) if result.code == 200: print "success" else: print "error"
but returns success
, wrong password. doing wrong?
change line
request = urllib2.request("https://github.com/")
to
request = urllib2.request("https://api.github.com/")
try change credentials. working me.
tested on
~/ $ python2 --version python 2.7.6 ~/ $ uname -a linux wlysenko-aspire 3.13.0-37-generic #64-ubuntu smp mon sep 22 21:28:38 utc 2014 x86_64 x86_64 x86_64 gnu/linux
Comments
Post a Comment