So my issue is with the Python Library for the JIRA API. We are using JIRA as a asset management database (Yes I know its normal used by dev's and we use it for that as well but this was a case were it worked well) to keep track of are server configs (Memory, CPU, Location on the Rack ..etc..)
Using this function I am having it create a Issue under a Project and pull the information for the fields from another API.
(note that I cant give clues as to who I work for so the code is edited - however it all works expect when i add one line)
def create_compute_node_in_jira(self, compute_node_name ,user_name, password, info_dic):
help_obj = helper()
jira = JIRA("https://",basic_auth=(user_name,password))
#Uses a dic to create the fields / info for the Issue
issue_dict = {
'project': {'key': <project>},
'summary': compute_node_name,
'issuetype': {'name': 'Server Hardware'},
'customfield_10500': str(info_dic["Hostname"]),
'customfield_11007': {'value': str("2U")},
'customfield_11006': str(info_dic["Aggr0-IP"]),
'customfield_10510': {'value': str(7)},
'customfield_10501': str(info_dic["Serial-Number"])
'customfield_10502': {'value': str(<server>)},
'customfield_10503': str(help_obj.data_parser_sm(info_dic["Hostname"])),
'customfield_10509': {'value': str("<OS>")},
'customfield_10504': {'value': str("<mem>")},
'customfield_10505': str(help_obj.data_parser_cpu(info_dic["CpuType"])),
'customfield_10507': {'value': str(info_dic["Cpu-Core"])},
'customfield_10508': {'value': str(<OS Version>)},
'customfield_11008': {'value': str("CMH")}
}
jira.create_issue(fields=issue_dict)
return "[*]Created ticket" # Should exit script after this is returned
The line - 'customfield_11008': {'value': str("CMH")} - causes the function to return the following expection:
jira.utils.JIRAError: JiraError HTTP 400
text: Option id 'null' is not valid
url: https:///rest/api/2/issue
however when i omit that line it runs with out a problem. I tried CMH lower case - capital ..etc.. and it still breaks the scripts. I even went through the web gui and copied the "CMH" entry in another ticket and it stilled caused a problem. Has anybody seen this before / have any guesses as to why it is breaking ?
So after a while of playing around with JIRA I found out it was my own mistake. It seems this error is caused when you post to a field using the API a "value" that it does not understand. A example was I was using the wrong custom field and the JIRA Field that I was posting to was not setup to take the value I was using.
You will see this error when the field's value is expected to match an option list, and you are trying to send a value which is not on this list.
Related
So I’m having some difficulty with my code. The code works but for some reason it only post one string instead of having all the strings posted in Jira. for example, up to the point that you see the #print(username, response), in the terminal I see all responses being printed in on screen. So it works great up to that point but the moment I send the same variable such as response through the Jira Dictionary called issue_dict, it creates the Jira but with only one of the responses and not all. I’ve tried doing something like response[x] but it just gives me an error that string indices must be integers. I’m not quite sure what else to do to be able to iterate through this so I can post all the results in the Description/body of a Jira ticket.
Ideally I would love to have both the user and the response in the description part. I’ve tried to do this with a List but I seem to get the same results where only one string gets printed. Anyone have done anything similar to post results in Jira?
Here is the code:
import jira from JIRA
for i in range(1,3):
user = os.getenv(‘USER’ + str(i))
pass = os.getenv(‘PASS’+ str(i))
headers = {
'X-Requested-With': 'Curl',
}
response =requests post('https://API-Address', headers=headers, auth=(USER,PASS))
root = ET.fromString(response.text) # Parses the JSON into text
for x in root.iter(’text’): #all this is doing is iterating through the file root and finding the text and saving the substring in response.
response = x[2].text
#print(username, response)
issue_dict = {
'project': {'id': 123},
'summary’:’My Jira Using Py',
'description': response, #This is the current issue!
'issuetype': {'name': 'Bug'},
}
new_issue = jira.create_issue(fields=issue_dict)
Is it possible to know the number of items in a group library?
I tried with f'groups/{group["id"]}/drive', which returns lots of information about the library, but doesn't include the total number of files.
EDIT (followup to Popkornak's answer)
I have tried using the $count parameter, but it doesn't work. Here is the result of the query with and without $count:
> print(requests.get('https://graph.microsoft.com/v1.0/groups/<group-id>/drive',
headers={'ConsistencyLevel': 'eventual', 'Authorization': '<...>'},
params={'$select': 'id', '$count': 'true'}).json())
{'error': {'code': 'invalidRequest', 'message': '$count is not supported on this API. Only URLs returned by the API can be used to page.', 'innerError': {'date': '2022-01-04T16:46:32', 'request-id': '<...>', 'client-request-id': '<...>'}}}
> print(requests.get('https://graph.microsoft.com/v1.0/groups/<group-id>/drive',
headers={'ConsistencyLevel': 'eventual', 'Authorization': '<...>'},
params={'$select': 'id'}).json())
{'#odata.context': 'https://graph.microsoft.com/v1.0/$metadata#drives(id)/$entity', 'id': '<...>'}
Use $count parameter in your query, reffer to oficial Microsoft documentation:
https://learn.microsoft.com/en-us/graph/query-parameters
Please keep in mind that if it will throws an error about not supported parameter use
Header:
Key: “consistencylevel” Value: “eventual”
I was able to write the code to get the details from SAP thru BAPI_USER_GET_DETAIL, here is attached code to get the email from SAP backend:
import pyrfc
from pyrfc import Connection
setup= pyrfc.Connection(user=X , passwd=Y , mshost=Z , sysid=A , client=B , msserv= C , group=D )
result=setup.call(BAPI_USER_GET_DETAIL, USERNAME=abc)
print (result['ADDRESS']['E_MAIL'])
Expected Result: abc#xyz.com
I am in need to update email address for particular user in SAP, after researching found that by using BAPI_USER_CHANGE we can update new mail address but tried many times with no luck!
Can anyone please help in getting the correct syntax to run BAPI_USER_CHANGE in Python?
First of all, your get BAPI is also a bit of incorrect, maybe on old versions of PyRFC it worked but now pyrfc module has Connection object, not connection and your code throws compilation error. It should be as follows:
import pyrfc
from pyrfc import Connection
RIS=pyrfc.Connection(user='USER', passwd='pw', ashost='hostey.com', sysid='KEK', sysnr='00', client='200', lang='EN', trace='3')
result=RIS.call("BAPI_USER_GET_DETAIL", USERNAME='MUELLER')
print(result['ADDRESS']['FULLNAME'])
Secondly, change BAPI is called the same as get BAPI, for me this code worked
ADDR = { "E_MAIL": 'wazawaza#mail.com'}
ADDX = { "E_MAIL": 'X'}
changed=RIS.call("BAPI_USER_CHANGE", USERNAME='MUELLER', ADDRESS=ADDR, ADDRESSX=ADDX)
print(changed["RETURN"])
it should show you smth like this output if executed correctly
[{'TYPE': 'S', 'ID': '01', 'NUMBER': '039', 'MESSAGE': 'User MUELLER has changed', 'LOG_NO': '', 'LOG_MSG_NO': '000000', 'MESSAGE_V1': 'MUELLER', 'MESSAGE_V2': '', 'MESSAGE_V3': '', 'MESSAGE_V4': '', 'PARAMETER': '', 'ROW': 0, 'FIELD': 'BNAME', 'SYSTEM': 'T90CLNT090'}]
Weirdly new email does not showed neither with BAPI call nor in SE37, but perfectly showed in SU01.
I thinks this is because of the long char field in BAPI structure which prevents it from showing correctly. Maybe this was the reason why you considered your call unsuccessful?
For any "Update BAPI" you need to call BAPI_TRANSACTION_COMMIT right after your BAPI call in order to actually commit the changes to the database.
Make sure the BAPI_TRANSACTION_COMMIT is executed on the same "connection", because it needs to run in the same backend user session.
I'm trying to debug a script that's trying to talk to RT (Request Tracker) and I'm getting the following output:
RT/3.6.6 409 Syntax Error
# Syntax Error
>>ARRAY(0x2b3495f37750)
I have no idea what this error means in the context of RT given the astounding lack of detail making it difficult to debug. Here's the associated code for a little context, it's a script trying to create a ticket.
import requests
def combDicts(dicts):
out = {}
for d in dicts:
out.update(d)
return out
operPath = 'ticket/new'
credentials = {'user': 'myuser', 'pass': 'mypassword'}
content = {
'content': {
'id': 'ticket/new',
'Subject': 'Python Script Test',
'Queue': 'General - unassigned',
}
}
r = requests.post('https://rt.hdms.com/REST/1.0/' + operPath, params=combDicts((credentials, content)), verify = False)
print r.text
If I comment out all but the Queue line of the content dict the error changes to:
RT/3.6.6 409 Syntax Error
# Syntax Error
>> Queue
The crux of my question is this: Does anyone know what this error means or know where I can find documentation on what all the RT errors are and what could cause them?
You'll find much more information in the logs on the RT server itself, especially if you up the log level to debug. You might have better luck using one of the python libraries available for calling RT. However, the version of RT you're running is fairly old, released in Jan. 2008. You may have trouble using current libraries with an old version of RT.
I have server-side code that calls the Google geocoding API, like this:
http://maps.google.com/maps/geo?q=40.714224,-73.961452&output=json&sensor=false&key=API_KEY
where API_KEY is my API key. I get a JSON reply, as expected, but the reponse is always 602 (Unknown Address). Is my URL wrong? (I've also tried the URL in the Google docs, but that returns a status: 'REQUEST_DENIED'.
What else could be wrong?
Update:
Well, it seems to actually be a mistake in my implementation, not the URL. This was how I did it:
api_params = {
'q': '40.714224,-73.961452',
'sensor': 'false',
'key': KEY,
'output': 'json'
}
# make the api call
http_response = urllib.urlopen('http://maps.google.com/maps/geo',
urllib.urlencode(api_params))
r = json.load(http_response)
but changing it to:
api_params = {
#'q': str(lat) + ',' + str(lng),
'q': '40.714224,-73.961452',
'sensor': 'false',
'key': KEY,
'output': 'json'
}
# make the api call
http_response = urllib.urlopen('http://maps.google.com/maps/geo?q='+api_params['q']+'&output=json&sensor=false&key='+api_params['key'])
r = json.load(http_response)
print r
fixes the problem. So my new question is, what's wrong with the first one?
The first one executes POST request, the second - GET request.
You may also want to use the urllib.urlencode function for concatenation.
But the easiest way is to use geopy.
Try using a HTTP watcher to make sure that this is the actual URL that is being sent within your application. There could be a chance that it isn't being encoded correctly or maybe is being incorrectly assembled. Since you aren't getting request denied and we were able to get a good response when we viewed it directly it seems that could be the best place to start. Hope that helps!