在循环中调用函数在Python中不起作用

破坏个人电脑

我有一个将创建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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在循环中调用setTimeout函数不起作用

For循环在python函数中不起作用

atoi函数在for循环中不起作用

循环中的Readline()在python中不起作用

为什么函数`load` 在`lapply` 中不起作用,而在`for` 循环中起作用?

startswith() 函数在 while 循环中不起作用,但在 for 循环中起作用?蟒蛇

+ =在For循环中不起作用

在python中循环并创建JSON文件的函数不起作用

For 循环在 Python 中的函数内部不起作用

Python-网页抓取,函数中的for循环不起作用

Java:随机函数在for循环中不起作用

Math.random()函数在for循环中不起作用

JavaScript 函数在表单循环中不起作用

getline() 函数在 while 循环中不起作用

angular.isArray 函数在循环中不起作用

Equals 函数在 While 循环中不起作用

为什么我的函数在循环中不起作用?

Excel 报告 - 函数 hlookup 在嵌套 for 循环中不起作用

For 循环中的嵌套 If 循环不起作用 (Python)

杀死通过infinte循环中的system()函数运行的子进程在perl中不起作用

Python函数在循环内不起作用

为什么这在for循环中起作用,但在forEach中却不起作用?(数组不是构造函数错误)

Python:映射调用函数不起作用

从HTML调用Python函数不起作用

Python Selenium driver.get()在for循环中不起作用

Python字典更新在for循环中不起作用

Python BeautifulSoup find_all()在for循环中不起作用

在不起作用的while循环中减去| Python

Python:break 语句在 for 循环中不起作用