Flask
-
[flask] python - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start bytePrograming/python 2021. 11. 22. 10:42
flask로 백엔드 서버를 구축중이다. 문제 발생의 주요 부분은, 프론트로부터 전달받은 이미지(bytes) 파일을 celery worker에게 전달해주는 과정에서 bytes 전송시 string으로 형변환 해서 넘겨줘야한다. (message broker는 'redis' 사용) 그런데, decode('utf-8') 함수를 사용해 bytes to string 형변환을 하니 아래와 같은 에러가 뜬다. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 파이썬은 기본적으로 'utf-8' 문자 포맷을 사용하는데 전달받은 이미지 파일의 포맷이 달라서 생기는 문제였다. (utf-16이라는 말이 있음) 실제로 ..
-
[CORS] react & flask - Access to XMLHttpRequest at 'http://localhost:8080/' from origin 'http://localhost:3000' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when ..Frontend 2021. 11. 2. 15:03
최근 ReactJS로 웹 페이지를 만들고있다. 이 웹 페이지는 파일을 업로드하는 기능이 있는데, 업로드 과정에서 CORS 에러가 발생됐다. React는 localhost:3000을 사용하고 flask는 localhost:8080 포트를 사용한다. 굳이 node.js를 사용하지 않고 flask를 사용한 이유는, AI 모델과 연동이 되기 때문에 python 기반의 서버로 구축하는 것이고 django에 비해 구축이 가벼워서 채택했다. [문제 발생] react(localhost:3000) post-> flask(localhost:8080) Access to XMLHttpRequest at 'http://localhost:8080/test' from origin 'http://localhost:3000' has ..