jamalex / notion-py

Unofficial Python API client for Notion.so
MIT License
4.3k stars 473 forks source link

TypeError: Object of type NotionDate is not JSON serializable #254

Open clebov opened 3 years ago

clebov commented 3 years ago

trying to add a new row and populate a date but I'm getting a type error

image

here is my code where I'm trying to assign a DateTime object in my list to the date property of the new row

cv = client.get_collection_view(page)
row = cv.collection.add_row()
row.Due = Canvas.assignment_details_list[0][1]

tried to use datetime.now() instead of what was in my list and I still get the same TypeError

image

not sure if I'm assigning the date property the wrong way or if its something else but any help with this is appreciated

Daveismus commented 3 years ago

I've got the same error

Daveismus commented 3 years ago

Can you share how the row.Due is done?

Also i think it should be due(lowercase)

clebov commented 3 years ago

so im grabbing a string from canvas and I'm parsing it. then I use the .striptime method from datetime to convert the string to a datetime format. here is the code for how I parse and save the data for the date.

x = attributes_dump.find('due_at')
    if x != -1:
        z = attributes_dump.find(',',x)
        due_at_date = str(attributes_dump[x+len('due_at='):z])
        due_at_date = due_at_date.replace('T', ' ')
        due_at_date = due_at_date.replace('Z', '')

        # if there is a due date format and cast it to a datetime object
        try: 
            due_at_date = datetime.strptime(due_at_date+'.0', '%Y-%m-%d %H:%M:%S.%f')
        except:
            pass
Daveismus commented 3 years ago

Okay, can you try to use

row.due = NotionDate(get_your_date) 

For me this did the Trick

You Fund notion date inside the collection package

clebov commented 3 years ago

so I did that and now im not getting an error but now the date field is not being populated with the data I want. even when I use date.today

Daveismus commented 3 years ago

Hm, weird, than i have no clue, how to solve this