From 76ca83cb87cdfda2e08a62e4092cc9f255c5283e Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 2 Jul 2009 03:56:24 -0400 Subject: [PATCH] Fixed credential verification with Basic (HTTP) Auth; previously, it assumed that passing in credentials meant you knew what you were doing. I take full blame for that act of idiocracy, but it's fixed now. --- tango.py | 8 +++++++- tango3k.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tango.py b/tango.py index 5313cfa..0994257 100644 --- a/tango.py +++ b/tango.py @@ -40,7 +40,13 @@ class setup: self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password) self.handler = urllib2.HTTPBasicAuthHandler(self.auth_manager) self.opener = urllib2.build_opener(self.handler) - self.authenticated = True + try: + test_verify = simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json")) + self.authenticated = True + except HTTPError, e: + if self.debug is True: + print e.headers + print "Huh, authentication failed with your provided credentials. Try again? (" + str(e.code) + " failure)" # OAuth functions; shortcuts for verifying the credentials. def fetch_response_oauth(self, oauth_request): diff --git a/tango3k.py b/tango3k.py index c707aae..ba3d771 100644 --- a/tango3k.py +++ b/tango3k.py @@ -42,7 +42,13 @@ class setup: self.auth_manager.add_password(None, "http://twitter.com", self.username, self.password) self.handler = urllib.request.HTTPBasicAuthHandler(self.auth_manager) self.opener = urllib.request.build_opener(self.handler) - self.authenticated = True + try: + test_verify = simplejson.load(self.opener.open("http://twitter.com/account/verify_credentials.json")) + self.authenticated = True + except HTTPError as e: + if self.debug is True: + print(e.headers) + print("Huh, authentication failed with your provided credentials. Try again? (" + str(e.code) + " failure)") # OAuth functions; shortcuts for verifying the credentials. def fetch_response_oauth(self, oauth_request):