I'm trying to make an API Spotify checker on Python
I was able to get this code working, but I noticed something that could potentially create a bug in my system.
With this code (having inputted bad login:pass):
with requests.Session() as c: header={ 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1', 'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'application/json, text/plain, */*', } c.cookies.set('__bon', 'MHwwfC0xNDAxNTMwNDkzfC01ODg2NDI4MDcwNnwxfDF8MXwx') get = c.get('https://accounts.spotify.com/en/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F') print(get.content) if 'Spotify</title>' in str(get.content): csrftoken = get.cookies['csrf_token'] login_data = dict(remember="true",username=usr, password=pwd, csrf_token=csrftoken) page = c.post('https://accounts.spotify.com/api/login', data=login_data, headers=header) print(page.content) if 'displayName' in str(page.content): valid = False page = c.post('https://www.spotify.com/us/account/overview/', data=login_data, headers=header) if 'Manage your family accounts' in str(page.content): print("You are family owner") valid = True
I get
b'{"error":"errorInvalidCredentials"}'
BUT, when I remove
c.cookies.set('__bon', 'MHwwfC0xNDAxNTMwNDkzfC01ODg2NDI4MDcwNnwxfDF8MXwx')
and I put a valid login credentials, I get the same error
b'{"error":"errorInvalidCredentials"}'
Which essentially means if Spotify ever changes the cookie or it expires, all accounts will return that error...which is a huge no no when making an auto account replacement.
Any suggestions on how to prevent this from happening?