- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023
03:37 PM
Hi @DeletedUser,
I'm going to guess authentication is failing because you're doing token.read() twice. The first call would read the entire file, presumably containing your API token. The second time you call that, there's nothing more to read, so it will essentially return nothing (and thus your headers would have no token). What you probably need to do is something more like:
import requests
tokenfile = open("./canvas.token", "r")
token = tokenfile.read()
if token == "":
print("No authentication found.")
quit()
requestUrl = "https://iuniversityprep.instructure.com/api/v1/courses"
headers = {
"Authorization": "Bearer " + token
}
print(requests.get(requestUrl, headers=headers).json())
This was the first thing that stuck out to me, so it's possible there are other issues going on, but I think this should perhaps point you in the right direction.
-Chris
Who Me Too'd this solution
1
DeletedUser
Not applicable
Me Too date:
10-21-2023