Trouble authenticating with Jira API using Python package

I’m having issues connecting to our Jira installation using the Python JIRA package. Here’s my code:

from secret_stuff import *
import requests
from jira import JIRA

jira_connection = JIRA(server='https://ourcompanyjira.com/jira', basic_auth=('[email protected]', 'APITokenHere'))

print(jira_connection.get_projects())

When I run this, I get a 401 Unauthorized error. The message says ‘Basic Authentication Failure - Reason: AUTHENTICATED_FAILED’. I can log in to Jira just fine through the web interface, so I’m not sure what’s going wrong here. Any ideas on how to fix this authentication problem?

I encountered a similar issue when setting up Jira API authentication with the Python package. My experience suggests that the problem might be due to using your regular Jira password instead of an API token. Atlassian requires a dedicated API token for these connections. You can create this token by logging into your Atlassian account and navigating to the security settings where you can generate a new token. Once the token is generated, replace your password with it in the basic_auth field. Also, check that your server URL is correct and properly formatted with https://. If the error persists, consider verifying that your network or firewall settings are not interfering with the connection.

I’ve worked extensively with the Jira API, and one common pitfall is misunderstanding the authentication requirements. Ensure you’re using an API token, not your regular password. Additionally, double-check your server URL - it should include the base URL only, without ‘/jira’ at the end. Try modifying your code like this:

jira_connection = JIRA(server='https://ourcompanyjira.com', basic_auth=('[email protected]', 'ActualAPITokenHere'))

If issues persist, verify your network isn’t blocking the connection. Some corporate environments require additional proxy configuration. You might need to add a ‘proxies’ parameter to your JIRA constructor if that’s the case.

Lastly, ensure your API token has the necessary permissions. Sometimes, tokens are created with limited access, which can lead to authentication failures for certain operations.

Hey, had similar issues b4. make sure ur using an API token, not ur regular password. go to atlassian account settings and generate a new token. replace ‘APITokenHere’ with the actual token. also double-check the URL - sometimes a typo can mess things up. good luck!