You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hello,
I'm trying to create an issue using the jira/JIRA python library. I've got it to connect with token_auth, but I'm now getting a JiraError HTTP 404 'No project found'. Copy-pasting the exact path from the error into google, I get a successful HTML readout (showing the project owner, key, etc.). My code is below:
#Some of the below imports unused/used in other parts of the code
import requests
from requests.auth import HTTPBasicAuth
import urllib.request
import json
from jira import JIRA
import pandas
from collections import defaultdict
import xlsxwriter
#code to import from another API into a dict, want to parse parts of this dict into jira eventually
options = {
'server': 'https://its.<mywebsite>.com',
'verify': True
jira = JIRA('https://its.<mywebsite>.com')
auth_jira = JIRA(options=options, token_auth=('<myuser>@<mywebsite>.com', '<api_token>'))
new_issue = jira.create_issue(project='TESTPROJ', summary='New issue from jira-python', description='Look into this one', issuetype={'name': 'Task'})
And below is the error I get:
JIRAError: JiraError HTTP 404 url: https://its.<mywebsite>.com/rest/api/2/project/TESTPROJ
text: No project could be found with key 'TESTPROJ'.
response headers = {'Date': 'Thu, 02 Nov 2023 16:36:29 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Set-Cookie': '<cookie>'; Expires=Thu, 09 Nov 2023 16:36:29 GMT; Path=/, '<some_path>'; Expires=Thu, 09 Nov 2023 16:36:29 GMT; Path=/; SameSite=None; Secure', 'X-AREQUESTID': '<data>', 'X-ANODEID': '<data>', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Security-Policy': 'sandbox', 'Strict-Transport-Security': 'max-age=31536000', 'X-AUSERNAME': 'anonymous', 'Cache-Control': 'no-cache, no-store, no-transform', 'Content-Encoding': 'gzip', 'Vary': 'User-Agent'}
response text = {"errorMessages":["No project could be found with key 'TESTPROJ'."],"errors":{}}
I redacted whatever I thought might've warranted redaction, sorry if I took something important out.
I'm thinking the problem might reside in the 'its...' part of the url, but using any of the urls I've seen in other documentation ('<mysite>.atlassian.net' or 'jira.<mysite>.com') does not connect for both python and in google. Hoping this doesn't mean I will not be able to connect.
I've tried using the HTTPRequests method, but could not get it to not error out before even pinging the server, let alone getting a response, so I'd appreciate help related to this library if possible. Thanks for any help in advance.
Hi,
can you try
basic_auth = ('<myuser>@<mywebsite>.com', '<api_token>')
instead of token_auth
I've tried 'basic_auth', as well as every combination of my username, email, password, API key, and basic_auth/token_auth, to no avail.
Trying to get a response from Jira at all, I wrote a script to just read out the description of a known issue in a different project, but I got a 401 not authorized error. I know my API token is correct, so I'm thinking it might be on the Jira side blocking me from connecting (I'm project owner so not sure why I'd not have API access, but that's my best theory). I'm talking with an internal IT guy right now, hopefully he can find out if that's the issue.
One thought I had was it could be a firewall issue, although I'm not quite sure what program to create the accepting rule for. I'll try a few rules and update here if it was either the Jira side issue or the firewall issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here a sample i'm using to make a post with Python
token = "******k544*******"
r = requests.post("https://myInstance/rest/api/2/search",json=payload,headers={'Authorization': "Bearer " + token},verify=False)
print(r.status_code)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried your code but had to add the definition for 'payload'. I also tried my username, email, and just Bearer in that "Bearer " field:
token = "******k544*******"
payload=json.dumps(
{
"fields": {
"project":
{
"key": "TESTPROJ"
}
}
}
)
r = requests.post("https://its.<mysite>.com/rest/api/2/search",json=payload,headers={'Authorization': "Bearer " + token},verify=False)
print(r.status_code)
This returns '400' bad request error:
C:\Program Files\Spyder\pkgs\urllib3\connectionpool.py:1095: InsecureRequestWarning: Unverified HTTPS request is being made to host 'its.<mysite>.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
400
C:\Program Files\Spyder\pkgs\urllib3\connectionpool.py:1095: InsecureRequestWarning: Unverified HTTPS request is being made to host 'its.<mysite>.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
I'm not very familiar with how the 'json'/'requests'/'HTTPBasicAuth' libraries work, which is why I'd rather work with the 'jira-python' library as shown above, so I know what the code is doing. I'll look into what your code is trying to do, and what inputs it needs, but I've tried the requests library before and could not get it to stop throwing errors.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import requests
import urllib3
urllib3.disable_warnings() #use to hide warning, if working you will need to add a certificate to your code
token = "YOUR JIRA TOKEN"
"""
payload = {
"jql": "project = ABC",
"startAt": 0,
"maxResults":10
}
r = requests.post("https://atlassianSite/rest/api/2/search",json=payload,headers={'Authorization': "Bearer " + token},verify=False)
#print(r.status_code)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Sorry, forgot about this post. For whatever reason, the urllib3 and/or HTTPRequests libraries were not working for me, even when using the solution above. I reached out to my system admins, and they recommended using the Jira module of the 'Atlassian Python API' library. This worked wonderfully and gave me no hiccups, minus some undescriptive HTTP errors when I entered something wrong. The documentation is here:
https://atlassian-python-api.readthedocs.io/index.html
Below is the basis of the code I used to create an issue using a token:
from atlassian import Jira
jira = Jira(
url='https://its.<mywebsite>.com',
#most Jira sites follow '<mysite>.atlassian.net' or 'jira.<mysite>.com', but it shouldn't matter
token='<mytoken>'
)
JiraFields = {
'project':{'key':'TESTPROJ'},
'issuetype':{'id':'3','name':'Task','subtask':False},
'summary':'Test Code',
'reporter':{'name':'<myname>','key':'JIRAUSER00000'},
'description':'Test issue description',
}
jira.issue_create(JiraFields)
Note: This may not work in it's current state, as the fields are heavily shortened from what they look like on the Jira backend. I went to the Jira API readout of an existing issue in my project or one I have access to (e.g. https://its.<mysite>.com/rest/api/2/issue/TESTPROJ-1) and copy-pasted the field readouts for the fields listed above, and changed parts of those fields to suit my project/issue as necessary.
Note 2: This solution may only work for Jira Datacenter/Server and not for Jira Cloud.
Thanks @Mohamed Benziane for the help, even if I ended up finding another solution.
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.