KeyError on requesting from API


#1

Total noob here.

Using python and I’m trying to just get a non 400 response code. Not using flask as what I’m making is entire local, its not for a website, I don’t want my clients to auth or anything, I just want information for myself so I can better organize it.
Currently fails to launch with KeyError

oauth_client = patreon.OAuth(client_id, client_secret)
tokens = oauth_client.get_tokens(requests.get(“https://www.patreon.com/api/oauth2/v2/identity?fields[user]=about,created,email,first_name,full_name,image_url,last_name,social_connections,thumb_url,url,vanity”), redirect_uri=‘https://www.remoteitsupportwa.pw’)
access_token = tokens[‘my access token here’]

api_client = patreon.API(access_token)
user_response = api_client.get_identity()
user = user_response.data()
memberships = user.relationship(‘memberships’)
membership = memberships[0] if memberships and len(memberships) > 0 else None

The documentation is kinda confusing for just wanting to access information personally and not give out access to my patreons. Every other source of information on learning how to do this only gives examples using public APIs and is useless.


#2

Ok just getting 400 now. Using:

url = ‘https://www.patreon.com/api/oauth2/v2/identity?fields[user]=full_name
auth = patreon.OAuth(client_id, client_secret)
response = requests.get(url, auth=auth)

Its it absolutely required that I be using Flask though? Thats the only example I can find of how to correctly authenticate(using patreon module). All I want is data from my patreons, not to give them some kind of login button or whatever. A simple valid url request with my proper credentials seems impossible to find among all the features I don’t need.

edit:
maybe getting somewhere
url = ‘https://www.patreon.com/api/oauth2/v2/identity?fields[user]=first_name,full_name
bearer = ‘Bearer’ + token
header = {‘Authorization’: bearer}
test = requests.get(url, headers=header)

printing test.text returns
“Error trying to decode a non urlencoded string. Found invalid characters: {’[’, ‘]’} in the string: ‘fields[user]=first_name,full_name’. Please ensure the request/response body is x-www-form-urlencoded.”,“id”:“b5243341-50b1-49b1-83b6-0af4ff9424a3”,“status”:“400”,“title”:“Bad Request”}]}

so I’m fucking up sending the url in some very basic fashion

E2: ok apparently needs %5B and %5D as python reserves [] I guess. Now just code 401


#3

Hey there! Is there an error description you’re receiving with the 401 you’re now receiving? That, or can I get the request id?


#4

Yes its 401 now. The request ID? Im not sure what that is, is it part of the url I’m missing?


#5

It’s the id field in the response


#6

I think I found it:

“id”:“eabf6a98-69b6-4926-94e7-4216e5656670”,“status”:“401”,“title”:“Unauthorized”}]}