chriscas
Community Coach
Community Coach

Hi @BRANDTEGGERS,

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

View solution in original post

Who Me Too'd this solution