Using Authentication for a Student Account

Jump to solution
Community Member


I'm a student, and I'm making an application that restricts myself from doing certain things if I have missing assignments. However, I cannot get the authentication to work properly. I'm using an integration token from my user profile.

This is my code (Python):

I have tried many different things to try and fix this, but it doesn't seem to work. The response is always "{'status': 'unauthenticated', 'errors': [{'message': 'user authorization required'}]}"

Labels (3)
1 Solution
Community Coach
Community Coach


I'm going to guess authentication is failing because you're doing 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 =
if token == "":
	print("No authentication found.")
requestUrl = ""
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.


View solution in original post