我有一个将创建JIRA票证的功能/方法。我想在循环中调用该函数,以便可以将不同的描述传递到JIRA票证中。我有一个包含不同服务故障的CSV文件,因此该想法是为csv文件中的每一行创建JIRA。
我的JIRA方法
def jira_rest_call(description):
# Build the text for the JIRA ticket.
jira_summary = "Pro active Monitoring"
jira_assignee='USERID'
jira_description = description
priority = 'High'
labels_list = 'Production Failure';
# Build the JSON to post to JIRA
json_data = '''
{
"fields":{
"project":{
"id": "25102",
"key": "ABC"
},
"assignee":{"name":"%s"},
"summary": "%s",
"issuetype":{
"name":"Story"
},
"description": "%s",
"priority":{"name":"%s"},
"labels":["%s"]
}
}''' % (jira_assignee,jira_summary, jira_description,priority,labels_list)
# Set the root JIRA URL, and encode the username and password
url = 'https://jira-abb.net/rest/api/2/issue'
userpass = 'Z683050' + ':' + '*******'
encoded_u = base64.b64encode(userpass.encode()).decode()
headers = {"Authorization" : "Basic %s" % encoded_u}
headers={'Content-Type':'application/json'}
# Build the request
r = requests.post(url,auth=HTTPBasicAuth('Z683050', ''*******'), headers=headers, data=json_data)
# Send the request and grab JSON response
# response = urlopen(restreq, data)
# Load into a JSON object and return that to the calling function
return r
我正在从像这样的其他Python模块调用此方法-
def jira_creation():
with open ('test_duplicates_1.csv','r') as csv_file:
for i in csv_file:
print([i])
jira_rest_call([i])
我的CSV数据如下所示
PDFDownloader,Backend failed,100
ImageProcess,NullPointer,200
因此,jira_creation()
方法jira_rest_call()
仅在第一行中调用并创建了一个票证,但我希望有两张票证。
该代码有什么问题?
with open ('test_duplicates_1.csv','r') as csv_file:
for i in csv_file:
print([i])
jira_rest_call([i])
我什至测试了print语句(print([i])),它打印了两次,但是方法调用(jira_rest_call([i]))仅发生过一次。
您没有以正确的方式读取csv文件。尝试以下方法:
with open ('test_duplicates_1.csv','r') as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
print(row)
jira_rest_call(row['<column_name>']) # I don't know what the column names are in your csv file. Replace with the right one.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句