I'm a vibe programmer with Python accessing Jira. Once I have the framework of the code I need I'm sure I'll be fine to refine it. Getting started is proving a barrier to me with the new API.
I can form the URL to make an initial JQL query to return issues but I don't think I'm authenticating correctly prior to the query. Is there somewhere I can look to see an up to date example of authentication and query using Python?
I think my query is correctly formed because when I paste it in the browser I get data back. however I get not data in my Python code.
My authentication code snippet:
def auth_session(email, token):
s = requests.Session()
s.auth = (email, token)
s.headers.update({'Accept': 'application/json'})
return s
session = auth_session(args.user, token)
My query code snippet:
url = base_url.rstrip('/') + '/rest/api/3/search/jql?jql=project=WD01&fields=*all'print(url)
r = session.get(url)
r.raise_for_status()
data = r.json()
https://keiththomas.atlassian.net/rest/api/3/search/jql?jql=project=WD01&fields=*all
Hi,
Did you create correctly your token : Manage API tokens for your Atlassian account | Atlassian Support
Do you have any error message when you run the script ?
Here an example from the documentation The Jira Cloud platform REST API :
import requests
jira_base_url = mySite.atlassian.net
query = { 'jql': 'project = HSP' }
headers = { "Accept": "application/json" }
auth = HTTPBasicAuth("email@example.com", "<api_token>")
response = requests.get(
f"{base_url}/rest/api/3/search",
headers=headers,
auth=auth,
params=query
)
@Mohamed Benziane thank you for the response. I took your suggestion and
1. Added an extra line:
from requests.auth import HTTPBasicAuth
2. Added jql to the URL to avoid this error
As far as I can tell from the debugger I still see no issues:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.