JIRA创建:TypeError:时间戳类型的对象不可JSON序列化



所以这段代码以前工作过,现在我得到了一个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)

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>')
}

其文档位于此处

最新更新