Hi community,
I'm trying to connect to the REST API of our Jira Data Center instance (https://jira.globaldevtools.bbva.com
) using a Python script, but I'm stuck on a persistent authentication error.
My account has two-factor authentication (MFA) enabled.
My first attempt was to use basic_auth
with my email and an API Token. This failed with a 403: Basic Authentication has been disabled on this instance
error, which is expected.
Following best practices, I changed my connection method in Python to use a Bearer Token
in the headers. The code is as follows:
from jira import JIRA
jira_server = 'https://jira.globaldevtools.bbva.com'
api_token = 'MY_NEWLY_GENERATED_API_TOKEN'
headers = {
'Authorization': f'Bearer {api_token}'
}
jira = JIRA(server=jira_server, options={'headers': headers})
However, this results in a 401 Unauthorized: Client must be authenticated to access this resource
error.
I have revoked and regenerated the API Token multiple times, copying it very carefully to ensure it is correct, but the result is always the same 401 error.
To rule out an issue with the Python library, I made a direct request using curl
from my terminal. The result was identical:
curl --request GET \
--url 'https://jira.globaldevtools.bbva.com/rest/api/2/myself' \
--header 'Authorization: Bearer MY_NEWLY_GENERATED_API_TOKEN' \
--header 'Accept: application/json'
Response: {"message":"Client must be authenticated to access this resource.","status-code":401}
Given that Basic Authentication is disabled and Bearer authentication with a freshly generated API token fails in both Python and curl
, what server-side Jira configurations could be causing this consistent rejection?
Is there a specific user-level or group-level permission that my account needs to have in order to use the REST API?
Could this be related to an IP Allowlist that is blocking requests from external services like Google Colab (where I am running the script)?
Are there any other recommended authentication methods for corporate instances with MFA that I should consider?
Any guidance would be greatly appreciated, as I have exhausted the client-side solutions. Thank you!
Hi @JHON VIDAL FIGUEROA CESPEDES
There are no specific user-level or group-level permissions that you need to interact with the API. For example, if your user can create an issue in Jira through the browser than you can create an issue using the rest API as long as you provide the same credentials.
"Could this be related to an IP Allowlist that is blocking requests from external services like Google Colab (where I am running the script)?" This sounds like it could be the issue, especially since you are on data center, I would check with your infrastructure team to see if there are any restrictions in place to prevent this connection. One thing you could try is pinging your Jira server from the environment where you are running your code.
What API endpoint are you sending a request to? I would try one that you are guaranteed to have access to, like getting a specific issue that you have verified you can view in the broswer. Hope this helps some :)
Thanks,
Jackson
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.