JSON对象不是serializab类型

2024-04-20 10:23:38 发布

您现在位置:Python中文网/ 问答频道 /正文

所以这段代码以前有效,现在我得到了一个JSON错误。我在google上搜索了修正的日期时间和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)

Tags: 代码importdfinputindexjirapasswordissue
1条回答
网友
1楼 · 发布于 2024-04-20 10:23:38

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的文档

相关问题 更多 >