Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Function Returns None even though Return is stated

Code
import requests

x = input("Gib email pls")

def CheckReg(page): #Checks if amazon account exists.
    try:
        with ss as requests.Session:
            ss.headers.update(
                {
                    'Host': 'www.amazon.com',
                    'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25',
                    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                    'Accept-Language': 'en-US,en;q=0.5',
                    'Accept-Encoding': 'gzip, deflate, br',
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'DNT': '1',
                    'Connection': 'keep-alive',
                    'Upgrade-Insecure-Requests': '1'
                })
            r = ss.get('https://www.amazon.com')
            cookies = r.cookies
            r = ss.post('https://www.amazon.com/ap/register?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26ref_%3Dgno_newcust?&email={}'.format(page), cookies=cookies)
            if 'You indicated you are a new customer, but an account already exists with the e-mail' in r.text:
                return True
            elif 'Create your Amazon account' in r.text:
                return False
            else:
                return r.text
    except:
        pass

if __name__ == '__main__':
    y = CheckReg(str(x))
    print(y)

It returns "None"

Any idea what's the problem behind this ?
The ss variable is not defined correctly.
Thanks man, Changed

Code
with ss as requests.Session:
to
Code
with requests.Session() as ss:
I guess the main problem is that exception is being ignored, then the function returns nothing and the user can't investigate what actually went wrong.

there's:
Code
try:
except:
   pass

You could replace it with:
Code
try:
except Exception as e:
   print(str(e))


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by SentienceOct 23, 2022 04:04 PM 10 294 Oct 23, 2022 04:04 PM
Last Post: Sentience
[C] by FhackMar 2, 2022 03:52 AM 4 307 Mar 2, 2022 03:52 AM
Last Post: Fhack
[C#] by ๖ۣۜchαmєllєσJan 2, 2020 04:29 PM 3 246 Jan 2, 2020 04:29 PM
Last Post: Stanley