Why do I get a 401 status code from the discord api?

Viewed 60

I'm trying to validate discord token, sending requests to the discord api, this was working but for some reason it stopped, this is my code:

def validate():                           
 headers = {'Content-Type': 'application/json', 'authorization': "my_token_here"}            
 request = requests.get("https://discordapp.com/api/v6/users/@me/library", headers=headers)  
 if(request.status_code == 200):                
  print("\033[32m[+] Valid Token.\033[m")   
 else:                                          
  print("\033[33m[-] Invalid Token.\033[m")

I put my bot token and still the status is 401, it was working before, can someone help me and explain what happened

Edit:

I noticed that I had placed a slash after library and then I started to receive the unauthorized code 401, even though the token is valid, why does this happen?

1 Answers

Try sending the call using HTTP and not HTTPS. I'm not sure this will solve the problem, but it might be worth a try.

Difference between HTTP and HTTPS:HTTPS is HTTP with encryption. The only difference between the two protocols is that HTTPS uses TLS (SSL) to encrypt normal HTTP requests and responses. As a result, HTTPS is far more secure than HTTP. A website that uses HTTP has http:// in its URL, while a website that uses HTTPS has https://.

Also, make sure that all parts of the address are spelled correctly. And if the API you are referring to belongs to you and make sure it is defined properly.

Related