def getRewardsPoints(self): """ Returns rewards points as int """ # report activity postFields = urllib.urlencode( { "url" : bingCommon.BING_URL, "V" : "web" } ) url = "http://www.bing.com/rewardsapp/reportActivity" request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) with self.opener.open(request) as response: page = helpers.getResponseBody(response) if len(page) == 0: raise Exception("Rewards points page is empty. That could mean you are not signed up for rewards with this account") # There are instances where the account appears to be signed in, but really is not helpers.errorOnText(page, "You are not signed", "Temporary account ban: User was not successfully signed in.\n") # parse activity page s = page.index("t.innerHTML='") s += len("t.innerHTML='") e = page.index("'", s) rewardsText = page[s:e] if rewardsText == 'Rewards': # The account is banned raise helpers.BingAccountError("Banned from BingRewards: Could not get the number of rewards.") else: return int(rewardsText)
def getLifetimeCredits(self): """ Returns http://www.bing.com/rewards/dashboard Lifetime Credits The number of credits earned since day one of the account """ url = "http://www.bing.com/rewards/dashboard" request = urllib2.Request(url=url, headers=self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # parse dashboard page s = page.find('<div class="credits-right') d = page.find('<span class="credits-right') # There are instances where the account appears to be signed in, but really is not helpers.errorOnText( page, "You are not signed", "Temporary account ban: User was not successfully signed in.\n") if s != -1: s += len('<div class="credits-right') s = page.index('<div class="credits', s) s += len('<div class="credits') elif d != -1: d += len('<span class="credits-right') d = page.index('<div class="credits', d) d += len('<div class="credits') s = d else: s = page.index('<div class="data-lifetime') s += len('<div class="data-lifetime') s = page.index('<div class="data-value-text', s) s += len('<div class="data-value-text') s = page.index(">", s) + 1 e = page.index('</div>', s) result = int(page[s:e]) return result
def getLifetimeCredits(self): """ Returns http://www.bing.com/rewards/dashboard Lifetime Credits The number of credits earned since day one of the account """ url = "http://www.bing.com/rewards/dashboard" request = urllib2.Request(url = url, headers = self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # parse dashboard page s = page.find('<div class="credits-right') d = page.find('<span class="credits-right') # There are instances where the account appears to be signed in, but really is not helpers.errorOnText(page, "You are not signed", "Temporary account ban: User was not successfully signed in.\n") if s != -1: s += len('<div class="credits-right') s = page.index('<div class="credits', s) s += len('<div class="credits') elif d != -1: d += len('<span class="credits-right') d = page.index('<div class="credits', d) d += len('<div class="credits') s = d else: s = page.index('<div class="data-lifetime') s += len('<div class="data-lifetime') s = page.index('<div class="data-value-text', s) s += len('<div class="data-value-text') s = page.index(">", s) + 1 e = page.index('</div>', s) result = int(page[s:e]) return result
def test_errorontext(self): """ test exception from helper's errorOnText :return: """ err = 'Authentication has not been passed: Invalid password' # not found so no assertion output = helpers.errorOnText("", 'That password is incorrect.', err) # should raise if it sees an assertion self.assertRaisesRegexp(helpers.BingAccountError, "Invalid", helpers.errorOnText, 'That password is incorrect.', 'That password is incorrect.', err)
def __authenticateLive(self, login, password): """ Authenticates a user on bing.com with his/her Live account. throws AuthenticationError if authentication can not be passed throws urllib2.HTTPError if the server couldn't fulfill the request throws urllib2.URLError if failed to reach the server """ # print "Requesting bing.com" # request http://www.bing.com request = urllib2.Request(url = bingCommon.BING_URL, headers = self.httpHeaders) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # get connection URL for provider Live s = page.index('"WindowsLiveId":"') s += len('"WindowsLiveId":"') e = page.index('"', s) url = BingAuth._escapeString(page[s:e]) request = urllib2.Request(url = url, headers = self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) with self.opener.open(request) as response: referer = response.geturl() # get Facebook authenctication form action url page = helpers.getResponseBody(response) # get PPFT parameter s = page.index("sFTTag") s = page.index('value="', s) s += len('value="') e = page.index('"', s) PPFT = page[s:e] # get PPSX parameter ppsxParam = "" if ",M:" in page: ppsxParam = ",M:" elif ",g:" in page: ppsxParam = ",g:" elif ",j:" in page: ppsxParam = ",j:" else: ppsxParam = ",d:" s = page.index(ppsxParam) s += len(ppsxParam) e = page.index(",", s) PPSX = page[s:e] if PPSX[0] == "'": PPSX = PPSX[1:-1] # generate ClientLoginTime clt = 20000 + int(random.uniform(0, 1000)) # generate RenderCompleteTime renderTime = 130 + int(random.uniform(0, 100)) # generate ResourcesCompleteTime resourcesTime = renderTime + int(random.uniform(2, 5)) # generate ResourcesCompleteTime PLT = 870 + int(random.uniform(0, 250)) # get url to post data to s = page.index(",urlPost:'") s += len(",urlPost:'") e = page.index("'", s) url = page[s:e] postFields = urllib.urlencode({ "login" : login, "passwd" : password, "SI" : "Sign in", "type" : "11", "PPFT" : PPFT, "PPSX" : str(PPSX), "idsbho" : "1", "LoginOptions" : "3", "NewUser" : "1", "i1" : "0", # ClientUserSaved "i2" : "1", # ClientMode "i3" : str(clt), # ClientLoginTime "i4" : "0", # ClientExplore "i7" : "0", # ClientOTPRequest "i12" : "1", # LoginUsedSSL "i13" : "0", # ClientUsedKMSI "i14" : str(renderTime), # RenderCompleteTime "i15" : str(resourcesTime), # RenderCompleteTime "i16" : str(PLT), # PLT "i17" : "0", # SRSFailed "i18" : "__Login_Strings|1,__Login_Core|1," # SRSSuccess }) # get Passport page request = urllib2.Request(url, postFields, self.httpHeaders) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # Checking for bad usernames and password helpers.errorOnText(page, 'That password is incorrect.', 'Authentication has not been passed: Invalid password') helpers.errorOnText(page, "That Microsoft account doesn\\'t exist", 'Authentication has not been passed: Invalid username') # check if there is a new terms of use helpers.errorOnText(page, '//account.live.com/tou/accrue', 'Please log in (log out first if necessary) through a browser and accept the Terms Of Use') # get auth form url and contents authForm = re.search(r"<form.+action=\"([^\"]+)\".*?>(.+)?</form>", page) if authForm == None: filename = helpers.dumpErrorPage(page) raise AuthenticationError("Could not find login form:\ncheck " + filename + " file for more information") parser = HTMLFormInputsParser() parser.feed(authForm.group(2).decode("utf-8")) parser.close() postFields = urllib.urlencode(parser.inputs) # finish passing authentication url = authForm.group(1) request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Origin", "https://login.live.com") with self.opener.open(request) as response: page = helpers.getResponseBody(response) url = bingCommon.BING_URL request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", authForm.group(1)) with self.opener.open(request) as response: url = response.geturl() # if that's not bingCommon.BING_URL => authentication wasn't pass => write the page to the file and report if url.find(bingCommon.BING_URL) == -1: try: filename = helpers.dumpErrorPage(helpers.getResponseBody(response)) s = "check " + filename + " file for more information" except IOError: s = "no further information could be provided - failed to write a file into " + \ helpers.RESULTS_DIR + " subfolder" raise AuthenticationError("Authentication has not been passed:\n" + s)
def __authenticateLive(self, login, password): """ Authenticates a user on bing.com with his/her Live account. throws AuthenticationError if authentication can not be passed throws urllib2.HTTPError if the server couldn't fulfill the request throws urllib2.URLError if failed to reach the server """ # print "Requesting bing.com" # request http://www.bing.com request = urllib2.Request(url=bingCommon.BING_URL, headers=self.httpHeaders) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # get connection URL for provider Live s = page.index('"WindowsLiveId":"') s += len('"WindowsLiveId":"') e = page.index('"', s) url = BingAuth._escapeString(page[s:e]) request = urllib2.Request(url=url, headers=self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) with self.opener.open(request) as response: referer = response.geturl() # get Facebook authenctication form action url page = helpers.getResponseBody(response) # get PPFT parameter s = page.index("sFTTag") s = page.index('value="', s) s += len('value="') e = page.index('"', s) PPFT = page[s:e] # get PPSX parameter ppsxSearch = self.ppsxValue.search(page) if ppsxSearch == None: raise AuthenticationError( "Could not find variable 't' on Live login page") PPSX = ppsxSearch.group(1) # generate ClientLoginTime clt = 20000 + int(random.uniform(0, 1000)) # get url to post data to s = page.index(",urlPost:'") s += len(",urlPost:'") e = page.index("'", s) url = page[s:e] timestamp = int(round(time.time() * 1000)) # TODO: randomize times a bit? i16 = json.dumps({ "navigationStart": timestamp, "unloadEventStart": timestamp + 209, "unloadEventEnd": timestamp + 210, "redirectStart": 0, "redirectEnd": 0, "fetchStart": timestamp + 73, "domainLookupStart": timestamp + 73, "domainLookupEnd": timestamp + 130, "connectStart": timestamp + 130, "connectEnd": timestamp + 130, "secureConnectionStart": timestamp + 210, "requestStart": timestamp + 183, "responseStart": timestamp + 205, "responseEnd": timestamp + 205, "domLoading": timestamp + 208, "domInteractive": timestamp + 406, "domContentLoadedEventStart": timestamp + 420, "domContentLoadedEventEnd": timestamp + 420, "domComplete": timestamp + 422, "loadEventStart": timestamp + 422, "loadEventEnd": 0 }) postFields = urllib.urlencode({ "loginfmt": login, "login": login, "passwd": password, "type": "11", "PPFT": PPFT, "PPSX": str(PPSX), "LoginOptions": "3", "FoundMSAs": "", "fspost": "0", "NewUser": "******", "i2": "1", # ClientMode "i13": "0", # ClientUsedKMSI "i16": i16, "i19": str(clt), # ClientLoginTime "i21": "0", "i22": "0", "i17": "0", # SRSFailed "i18": "__DefaultLogin_Strings|1,__DefaultLogin_Core|1," # SRSSuccess }) # get Passport page request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", referer) with self.opener.open(request) as response: referer = response.geturl() page = helpers.getResponseBody(response) # Checking for bad usernames and password helpers.errorOnText( page, 'That password is incorrect.', 'Authentication has not been passed: Invalid password') helpers.errorOnText( page, "That Microsoft account doesn\\'t exist", 'Authentication has not been passed: Invalid username') # check if there is a new terms of use helpers.errorOnText( page, '//account.live.com/tou/accrue', 'Please log in (log out first if necessary) through a browser and accept the Terms Of Use' ) contSubmitUrl = self.formAction.search(page) if contSubmitUrl == None: raise AuthenticationError( "Could not find form action for continue page") url = contSubmitUrl.group(1) # get all form inputs formFields = self.inputNameValue.findall(page) postFields = {} for field in formFields: postFields[field[0]] = field[1] postFields = urllib.urlencode(postFields) # submit continue page request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", referer) with self.opener.open(request) as response: referer = response.geturl() page = helpers.getResponseBody(response) request = urllib2.Request(url=bingCommon.BING_URL, headers=self.httpHeaders) request.add_header("Referer", referer) with self.opener.open(request) as response: referer = response.geturl() # if that's not bingCommon.BING_URL => authentication wasn't pass => write the page to the file and report if referer.find(bingCommon.BING_URL) == -1: try: filename = helpers.dumpErrorPage( helpers.getResponseBody(response)) s = "check " + filename + " file for more information" except IOError: s = "no further information could be provided - failed to write a file into " + \ helpers.RESULTS_DIR + " subfolder" raise AuthenticationError( "Authentication has not been passed:\n" + s)
def __authenticateLive(self, login, password): """ Authenticates a user on bing.com with his/her Live account. throws AuthenticationError if authentication can not be passed throws urllib2.HTTPError if the server couldn't fulfill the request throws urllib2.URLError if failed to reach the server """ # print "Requesting bing.com" # request http://www.bing.com request = urllib2.Request(url = bingCommon.BING_URL, headers = self.httpHeaders) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # get connection URL for provider Live s = page.index('"WindowsLiveId":"') s += len('"WindowsLiveId":"') e = page.index('"', s) url = BingAuth._escapeString(page[s:e]) request = urllib2.Request(url = url, headers = self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) with self.opener.open(request) as response: referer = response.geturl() # get Facebook authenctication form action url page = helpers.getResponseBody(response) # get PPFT parameter s = page.index("sFTTag") s = page.index('value="', s) s += len('value="') e = page.index('"', s) PPFT = page[s:e] # get PPSX parameter ppsxSearch = self.ppsxValue.search(page) if ppsxSearch == None: raise AuthenticationError("Could not find variable 't' on Live login page") PPSX = ppsxSearch.group(1) # generate ClientLoginTime clt = 20000 + int(random.uniform(0, 1000)) # get url to post data to s = page.index(",urlPost:'") s += len(",urlPost:'") e = page.index("'", s) url = page[s:e] timestamp = int(round(time.time() * 1000)) # TODO: randomize times a bit? i16 = json.dumps({ "navigationStart": timestamp, "unloadEventStart": timestamp + 209, "unloadEventEnd": timestamp + 210, "redirectStart": 0, "redirectEnd": 0, "fetchStart": timestamp + 73, "domainLookupStart": timestamp + 73, "domainLookupEnd": timestamp + 130, "connectStart": timestamp + 130, "connectEnd": timestamp + 130, "secureConnectionStart": timestamp + 210, "requestStart": timestamp + 183, "responseStart": timestamp + 205, "responseEnd": timestamp + 205, "domLoading": timestamp + 208, "domInteractive": timestamp + 406, "domContentLoadedEventStart": timestamp + 420, "domContentLoadedEventEnd": timestamp + 420, "domComplete": timestamp + 422, "loadEventStart": timestamp + 422, "loadEventEnd": 0 }) postFields = urllib.urlencode({ "loginfmt" : login, "login" : login, "passwd" : password, "type" : "11", "PPFT" : PPFT, "PPSX" : str(PPSX), "LoginOptions" : "3", "FoundMSAs" : "", "fspost" : "0", "NewUser" : "1", "i2" : "1", # ClientMode "i13" : "0", # ClientUsedKMSI "i16" : i16, "i19" : str(clt), # ClientLoginTime "i21" : "0", "i22" : "0", "i17" : "0", # SRSFailed "i18" : "__DefaultLogin_Strings|1,__DefaultLogin_Core|1," # SRSSuccess }) # get Passport page request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", referer) with self.opener.open(request) as response: referer = response.geturl() page = helpers.getResponseBody(response) # Checking for bad usernames and password helpers.errorOnText(page, 'That password is incorrect.', 'Authentication has not been passed: Invalid password') helpers.errorOnText(page, "That Microsoft account doesn\\'t exist", 'Authentication has not been passed: Invalid username') # check if there is a new terms of use helpers.errorOnText(page, '//account.live.com/tou/accrue', 'Please log in (log out first if necessary) through a browser and accept the Terms Of Use') contSubmitUrl = self.formAction.search(page) if contSubmitUrl == None: raise AuthenticationError("Could not find form action for continue page") url = contSubmitUrl.group(1) # get all form inputs formFields = self.inputNameValue.findall(page) postFields = {} for field in formFields: postFields[field[0]] = field[1] postFields = urllib.urlencode(postFields) # submit continue page request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", referer) with self.opener.open(request) as response: referer = response.geturl() page = helpers.getResponseBody(response) request = urllib2.Request(url = bingCommon.BING_URL, headers = self.httpHeaders) request.add_header("Referer", referer) with self.opener.open(request) as response: referer = response.geturl() # if that's not bingCommon.BING_URL => authentication wasn't pass => write the page to the file and report if referer.find(bingCommon.BING_URL) == -1: try: filename = helpers.dumpErrorPage(helpers.getResponseBody(response)) s = "check " + filename + " file for more information" except IOError: s = "no further information could be provided - failed to write a file into " + \ helpers.RESULTS_DIR + " subfolder" raise AuthenticationError("Authentication has not been passed:\n" + s)
def authenticate(self, authType, login, password): """ throws ValueError if login or password is None throws AuthenticationError """ if login is None: raise ValueError("login is None") if password is None: raise ValueError("password is None") """ Authenticates a user on bing.com with his/her Live account. throws AuthenticationError if authentication can not be passed throws urllib2.HTTPError if the server couldn't fulfill the request throws urllib2.URLError if failed to reach the server """ # request http://www.bing.com request = urllib2.Request(url = bingCommon.BING_URL, headers = self.httpHeaders) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # get connection URL for provider Live urlSearch = self.winLiveId.search(page) if urlSearch == None: raise AuthenticationError("Could not find variable 'WindowsLiveId' on Live login page") url = urlSearch.group(1).decode("unicode_escape") request = urllib2.Request(url = url, headers = self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) page, referer = helpers.getResponses(self, request) # get PPFT parameter PPFTSearch = self.ppftValue.search(page) if PPFTSearch == None: raise AuthenticationError("Could not find variable 'PPFT' on Live login page") PPFT = PPFTSearch.group(1) # get PPSX parameter ppsxSearch = self.ppsxValue.search(page) if ppsxSearch == None: raise AuthenticationError("Could not find PassportRN variable on Live login page") PPSX = ppsxSearch.group(1) # generate ClientLoginTime clt = 20000 + int(random.uniform(0, 1000)) # get url to post data to urlSearch = self.urlPostValue.search(page) if urlSearch == None: raise AuthenticationError("Could not find variable 'urlPost' on Live login page") url = urlSearch.group(1) timestamp = int(round(time.time() * 1000)) # TODO: randomize times a bit? i16 = json.dumps({ "navigationStart": timestamp, "unloadEventStart": timestamp + 209, "unloadEventEnd": timestamp + 210, "redirectStart": 0, "redirectEnd": 0, "fetchStart": timestamp + 73, "domainLookupStart": timestamp + 73, "domainLookupEnd": timestamp + 130, "connectStart": timestamp + 130, "connectEnd": timestamp + 130, "secureConnectionStart": timestamp + 210, "requestStart": timestamp + 183, "responseStart": timestamp + 205, "responseEnd": timestamp + 205, "domLoading": timestamp + 208, "domInteractive": timestamp + 406, "domContentLoadedEventStart": timestamp + 420, "domContentLoadedEventEnd": timestamp + 420, "domComplete": timestamp + 422, "loadEventStart": timestamp + 422, "loadEventEnd": 0 }) postFields = urllib.urlencode({ "loginfmt" : login, "login" : login, "passwd" : password, "type" : "11", "PPFT" : PPFT, "PPSX" : str(PPSX), "LoginOptions" : "3", "FoundMSAs" : "", "fspost" : "0", "NewUser" : "1", "i2" : "1", # ClientMode "i13" : "0", # ClientUsedKMSI "i16" : i16, "i19" : str(clt), # ClientLoginTime "i21" : "0", "i22" : "0", "i17" : "0", # SRSFailed "i18" : "__DefaultLogin_Strings|1,__DefaultLogin_Core|1," # SRSSuccess }) # get Passport page request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", referer) page, referer = helpers.getResponses(self, request) # Checking for bad usernames and password helpers.errorOnText(page, "That password is incorrect.", "Authentication has not been passed: Invalid password") helpers.errorOnText(page, "That Microsoft account doesn't exist", "Authentication has not been passed: Invalid username") # check if there is a new terms of use helpers.errorOnText(page, "//account.live.com/tou/accrue", "Please log in (log out first if necessary) through a browser and accept the Terms Of Use") contSubmitUrl = self.formAction.search(page) if contSubmitUrl == None: raise AuthenticationError("Could not find form action for continue page") url = contSubmitUrl.group(1) # get all form inputs formFields = self.inputNameValue.findall(page) postFields = {} for field in formFields: postFields[field[0]] = field[1] postFields = urllib.urlencode(postFields) # submit continue page request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", referer) page, referer = helpers.getResponses(self, request) request = urllib2.Request(url = bingCommon.BING_URL, headers = self.httpHeaders) request.add_header("Referer", referer) with self.opener.open(request) as response: referer = response.geturl() # if that's not bingCommon.BING_URL => authentication wasn't pass => write the page to the file and report if referer.find(bingCommon.BING_URL) == -1: raise AuthenticationError("Authentication has not been passed:\n")
def __authenticateLive(self, login, password): """ Authenticates a user on bing.com with his/her Live account. throws AuthenticationError if authentication can not be passed throws urllib2.HTTPError if the server couldn't fulfill the request throws urllib2.URLError if failed to reach the server """ # print "Requesting bing.com" # request http://www.bing.com request = urllib2.Request(url=bingCommon.BING_URL, headers=self.httpHeaders) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # get connection URL for provider Live s = page.index('"WindowsLiveId":"') s += len('"WindowsLiveId":"') e = page.index('"', s) url = BingAuth._escapeString(page[s:e]) request = urllib2.Request(url=url, headers=self.httpHeaders) request.add_header("Referer", bingCommon.BING_URL) with self.opener.open(request) as response: referer = response.geturl() # get Facebook authenctication form action url page = helpers.getResponseBody(response) # get PPFT parameter s = page.index("sFTTag") s = page.index('value="', s) s += len('value="') e = page.index('"', s) PPFT = page[s:e] # get PPSX parameter ppsxParam = "" if ",M:" in page: ppsxParam = ",M:" elif ",g:" in page: ppsxParam = ",g:" elif ",j:" in page: ppsxParam = ",j:" else: ppsxParam = ",d:" s = page.index(ppsxParam) s += len(ppsxParam) e = page.index(",", s) PPSX = page[s:e] if PPSX[0] == "'": PPSX = PPSX[1:-1] # generate ClientLoginTime clt = 20000 + int(random.uniform(0, 1000)) # generate RenderCompleteTime renderTime = 130 + int(random.uniform(0, 100)) # generate ResourcesCompleteTime resourcesTime = renderTime + int(random.uniform(2, 5)) # generate ResourcesCompleteTime PLT = 870 + int(random.uniform(0, 250)) # get url to post data to s = page.index(",urlPost:'") s += len(",urlPost:'") e = page.index("'", s) url = page[s:e] postFields = urllib.urlencode({ "login": login, "passwd": password, "SI": "Sign in", "type": "11", "PPFT": PPFT, "PPSX": str(PPSX), "idsbho": "1", "LoginOptions": "3", "NewUser": "******", "i1": "0", # ClientUserSaved "i2": "1", # ClientMode "i3": str(clt), # ClientLoginTime "i4": "0", # ClientExplore "i7": "0", # ClientOTPRequest "i12": "1", # LoginUsedSSL "i13": "0", # ClientUsedKMSI "i14": str(renderTime), # RenderCompleteTime "i15": str(resourcesTime), # RenderCompleteTime "i16": str(PLT), # PLT "i17": "0", # SRSFailed "i18": "__Login_Strings|1,__Login_Core|1," # SRSSuccess }) # get Passport page request = urllib2.Request(url, postFields, self.httpHeaders) with self.opener.open(request) as response: page = helpers.getResponseBody(response) # Checking for bad usernames and password helpers.errorOnText( page, 'That password is incorrect.', 'Authentication has not been passed: Invalid password') helpers.errorOnText( page, "That Microsoft account doesn\\'t exist", 'Authentication has not been passed: Invalid username') # check if there is a new terms of use helpers.errorOnText( page, '//account.live.com/tou/accrue', 'Please log in (log out first if necessary) through a browser and accept the Terms Of Use' ) # get auth form url and contents authForm = re.search(r"<form.+action=\"([^\"]+)\".*?>(.+)?</form>", page) if authForm == None: filename = helpers.dumpErrorPage(page) raise AuthenticationError("Could not find login form:\ncheck " + filename + " file for more information") parser = HTMLFormInputsParser() parser.feed(authForm.group(2).decode("utf-8")) parser.close() postFields = urllib.urlencode(parser.inputs) # finish passing authentication url = authForm.group(1) request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Origin", "https://login.live.com") with self.opener.open(request) as response: page = helpers.getResponseBody(response) url = bingCommon.BING_URL request = urllib2.Request(url, postFields, self.httpHeaders) request.add_header("Referer", authForm.group(1)) with self.opener.open(request) as response: url = response.geturl() # if that's not bingCommon.BING_URL => authentication wasn't pass => write the page to the file and report if url.find(bingCommon.BING_URL) == -1: try: filename = helpers.dumpErrorPage( helpers.getResponseBody(response)) s = "check " + filename + " file for more information" except IOError: s = "no further information could be provided - failed to write a file into " + \ helpers.RESULTS_DIR + " subfolder" raise AuthenticationError( "Authentication has not been passed:\n" + s)