Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting 401-Unauthorized Error trying to access attachments

Linda Zhao December 27, 2023

This is what I am running:

import requests

from requests.auth import HTTPBasicAuth

import json

url = "https://foo.atlassian.net/wiki/api/v2/attachments"

auth = HTTPBasicAuth("foo.bar@foobar.com", "MY_API_TOKEN")

headers = {

  "Accept": "application/json",

}

response = requests.request(

  "GET",

  url,

  headers=headers,

  auth=auth

)

print(response)
and i get a 401 unauthroized error. I have created the API token and the email I am using is the admin email for my organization.
Is there something i'm missing here?

1 answer

0 votes
Tansu Akdeniz
Community Champion
December 27, 2023

Hi @Linda Zhao 

Welcome to the community.

Please take a look at this doc: Basic auth for REST APIs

Provide the encoded string in header.

Linda Zhao December 27, 2023

Thanks for the prompt reponse!

It is my understanding that in python requests

 

auth = HTTPBasicAuth("foo.bar@foobar.com", "MY_API_TOKEN")

accomplishes the same thing as adding that to the header,

nonetheless i also tried adding

headers = {

"Accept": "application/json",

"Authorization": "Basic ENCODED_STRING",

}

to no avail.

 

Linda Zhao December 27, 2023

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events