The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
Hello,
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): https://pastebin.com/D672jT0U
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'}]}"
Solved! Go to Solution.
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
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
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in