Getting 401 Unauthorized error when connecting to Jira using Python library

I’m having trouble connecting to our company’s Jira instance using the Python jira library. The authentication keeps failing even though I can log in through the web interface just fine.

Here’s what I’m trying to do:

from credentials import *
import requests
from jira import JIRA

options = {'server': 'https://ourcompany-jira.example.com/jira'}
jira_client = JIRA(options, basic_auth=('[email protected]', 'api_token_here'))

project_list = jira_client.projects()
print(project_list)

But I keep getting this error message:

HTTPError: 401 Client Error: Unauthorized
Basic Authentication Failure - Reason: AUTHENTICATED_FAILED

I can access Jira through the browser without any issues using the same credentials. Has anyone run into this before? What am I doing wrong with the authentication setup?

Check if your Jira instance needs different auth headers. I had this exact problem - our company proxy was stripping the auth headers. Try adding verify=False to see if it’s SSL issues, or manually add headers like headers={'Authorization': 'Basic base64encodedcreds'} to your requests. Some Jira setups also want the email format different - maybe try without the @domain part?

This happens when your Jira instance has different auth requirements than the web login. I ran into the same thing last year after our IT changed security policies. Check if your company uses SSO or SAML - you’ll need a completely different auth method if they do. Also verify your API token has the right permissions. Sometimes tokens get created but don’t inherit all the scopes they need. Try testing with a basic curl REST API call first to see if it’s a Python library problem or auth issue. If basic auth is disabled entirely, you’ll need to switch to OAuth or personal access tokens depending on your Jira version.

Had the same issue recently. You probably need an API token instead of your regular password. Even if you can log into Jira’s web interface fine, you’ll need to generate a specific API token in your user profile for scripts and apps. Make sure you’re actually using that token, not your password. Also check if your Jira admin disabled basic auth - some setups force OAuth instead. And double-check your server URL matches the API endpoint exactly, since they can be slightly different.