Authenticating with Jira API using Python and bypassing MFA

Hey folks, I’m having trouble with Jira API authentication in my Python script. It used to work fine with an API key, but now it’s not cooperating. I’ve enabled two-factor auth in Jira, and I thought the API key would let me skip that. But now my script just hangs during authentication.

Here’s a simplified version of what I was using before:

if api_key:
    jira_client = JiraConnection(
        server=jira_server,
        auth_token=api_key
    )

Does anyone know if there’s a special way to handle API authentication with MFA enabled? Or maybe I’m missing something obvious? Any tips would be super helpful!

I encountered a similar issue recently when working with Jira’s API. The solution that worked for me was using a Personal Access Token (PAT) instead of the API key. PATs are designed to work seamlessly with MFA-enabled accounts.

To create a PAT, go to your Jira account settings, find the ‘Security’ section, and look for ‘Create and manage API tokens’ or something similar. Generate a new token there.

Then, modify your Python code to use the PAT like this:

jira_client = JiraConnection(
    server=jira_server,
    basic_auth=("[email protected]", "your_personal_access_token")
)

This approach should bypass the MFA requirement and allow your script to authenticate successfully. Remember to keep your PAT secure, as it grants access to your account.

hey tom, i had the same headache. turns out, you gotta use a personal access token (PAT) now. go to your jira settings, look for API tokens, and make a new one. then use it like this:

jira_client = JiraConnection(
server=jira_server,
basic_auth=(“your_email”, “your_PAT”)
)

should work even with MFA on. good luck!

I’ve been in your shoes, Tom. When MFA was introduced on Jira, it disrupted many of our automated processes. After some trial and error, I discovered that creating an API token tailored to your application works best. Instead of using a password, you can generate a token from your user profile under Security. Once you have that token, update your Python code as follows:

from jira import JIRA

jira = JIRA(server="https://your-domain.atlassian.net",
            basic_auth=("[email protected]", "your-api-token"))

This method has been reliable for me even with MFA enabled, and it offers added security since you can revoke the token at any time without affecting your main credentials. I hope this insight helps.