๋ฐ์ํ
Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- ํ๋ค์ค
- MySQL
- ํ์ด์ฌ
- Streamlit๊ธฐ์ด
- ํ์ด์ฌ๊ณต๋ถ
- ์๋ฐํ๋ก๊ทธ๋๋ฐ
- ์คํธ๋ฆผ๋ฆฟ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ์๋ฐ์ด๋ณด
- java
- Pandas
- serverless
- ์๋ฐ์คํฌ๋ฆฝํธ ๊ณต๋ถ
- RESTful API
- JavaScript
- ์๋ฐ๊ธฐ์ด
- ์๋ฐ๊ณต๋ถ
- ์๋ฐ
- Android
- ์คํธ๋ฆผ๋ฆฟ ๊ธฐ๋ณธ
- ์๋๋ก์ด๋ ์คํ๋์ค
- Flutter
- ํ๋ค์ค๊ณต๋ถ
- ์น๋์๋ณด๋ ๊ธฐ์ด
- streamlit
- Streamlit๊ธฐ๋ณธ
- ์น๋์๋ณด๋ ์ ์
- db
- ์๋๋ก์ด๋ ์ฑ ๊ฐ๋ฐ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
Archives
- Today
- Total
ruriruriya
[RESTful API] Python MySQL- TypeError : Object of type datetime is not JSON serializable ๋ฐ์ ์์ธ๊ณผ ํด๊ฒฐ๋ฐฉ๋ฒ ๋ณธ๋ฌธ
๐Debugging Story
[RESTful API] Python MySQL- TypeError : Object of type datetime is not JSON serializable ๋ฐ์ ์์ธ๊ณผ ํด๊ฒฐ๋ฐฉ๋ฒ
๋ฃจ๋ฆฌ์ผใ 2023. 12. 7. 11:45๋ฐ์ํ
RESTful API ์์ ๋ฐ์ดํฐ๋ฅผ GETํ ๋
TypeError : Object of type datetime is not JSON serializable ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
1. ๋ฐ์์์ธ
datetime ์ ํ์ด์ฌ์์๋ง ์ฌ์ฉํ๋ ๋ฐ์ดํฐํ์ ์ผ๋ฏ๋ก json ํ์์ด ์๋๊ธฐ ๋๋ฌธ์ ๋์จ ์๋ฌ
2. ํด๊ฒฐ๋ฐฉ๋ฒ
๋ฐ๋ผ์ json์ ๋ฌธ์์ด์ด๋ ์ซ์๋ง ๊ฐ๋ฅํ๋ฏ๋ก ํ์ด์ฌ์ datetime ํ์ ์ ๋ฌธ์์ด๋ก ๋ฐ๊ฟ์ค์ผ ํ๋ค.
from flask import request
from flask_restful import Resource
from mysql_connection import get_connection
from mysql.connector import Error
class RecipeListResource(Resource):
def get(self) :
## ์ค๊ฐ ์๋ต ##
# datetime์ ๋ฌธ์์ด๋ก ๋ฐ๊ฟ์ค์ผ ํ๋ค.โ
i = 0
for row in result_list :
result_list[i]['created_at']= row['created_at'].isoformat()
result_list[i]['updated_at']= row['updated_at'].isoformat()
i = i + 1
## ์ดํ ์๋ต ##
๋ฐ์ํ