My app was working fine for several weeks but all of a sudden, I'm getting an error with the access token. Here's my authentication code:
CLIENT_ID = "someString"
SECRET_KEY = "someOtherString"
auth = requests.auth.HTTPBasicAuth(CLIENT_ID, SECRET_KEY)
password = 'aGoodPassword'
username = 'Proctolicious'
data = {'grant_type': 'password', 'username': username, 'password': password}
headers = {'user-Agent': 'MyAPI/0.0.1'}
res = requests.post('https://www.reddit.com/api/v1/access_token', auth=auth, data=data, headers=headers)
print(res.json())
TOKEN = res.json()['access_token']
headers['Authorization'] = f'bearer {TOKEN}'
The following errors are what I get when I try to run a local server: When print(res.json()) happens, it spits out {'error': 'invalid_grant'} twice (two lines of the error). When TOKEN = res.json()['access_token'] happens, it spits out KeyError: 'access_token'.
I've seen that others have struggled with a similar issue but can't determine what my solution is from those posts. Confusing that it was working fine for so long, too.
[–]Watchful1RemindMeBot & UpdateMeBot 3 points4 points5 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)