JIRA创建:TypeError:Timestamp类型的对象不是JSON可序列化的

时间:2018-11-07 19:53:29

标签: python json jira

因此此代码之前有效,现在我收到JSON错误。我用datetime和json.dump搜索了修复程序,但我想不出办法。我不确定在没有直接日期变量时如何在此代码中实现。

from jira import JIRA
import pandas as pd

df = pd.read_excel('JIRA.xlsx', header=0, index=False).dropna(how='all')

options = {'server': 'https://act.genpt.net'}

jira_user = input('User Name: ')
jira_password = input('Password: ')

jira = JIRA(options, basic_auth=(jira_user, jira_password))

for index, row in df.iterrows():
    summary = row[2]
    description = 'Research and assign attributes'
    owner = row[3]
    dueDate = row[4]

    issue_dict = {
        'project': 11208,
        'issuetype': {'name': 'Task'},
        'summary': summary,
        'priority': {'id': '7'},
        'description': description,
        'environment': 'PROD',
        'components': 'Item Type Clean Up',
        'customfield_10108': owner,
        'duedate': dueDate
        }

    new = jira.create_issue(fields=issue_dict)

1 个答案:

答案 0 :(得分:0)

pandas.datetime对象,例如datetime.datetime对象,不能json序列化,并且会导致这些错误。解决此问题的最佳方法是对日期时间进行字符串格式化,因为字符串是可哈希的:

for index, row in df.iterrows():
    summary = row[2]
    description = 'Research and assign attributes'
    owner = row[3]
    dueDate = row[4]

    issue_dict = {
        'project': 11208,
        'issuetype': {'name': 'Task'},
        'summary': summary,
        'priority': {'id': '7'},
        'description': description,
        'environment': 'PROD',
        'components': 'Item Type Clean Up',
        'customfield_10108': owner,
        # You will have to know the format of the datetime and
        # input that as the argument
        'duedate': dueDate.strftime('<date_format_here>')
        }

here所在的文档