notion-py icon indicating copy to clipboard operation
notion-py copied to clipboard

TypeError: Object of type NotionDate is not JSON serializable

Open clebov opened this issue 4 years ago • 6 comments

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

clebov avatar Jan 09 '21 22:01 clebov

I've got the same error

Daveismus avatar Jan 13 '21 10:01 Daveismus

Can you share how the row.Due is done?

Also i think it should be due(lowercase)

Daveismus avatar Jan 22 '21 14:01 Daveismus

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

clebov avatar Jan 22 '21 17:01 clebov

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

Daveismus avatar Jan 22 '21 19:01 Daveismus

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

clebov avatar Jan 23 '21 03:01 clebov

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

Daveismus avatar Jan 25 '21 09:01 Daveismus