[PyJWT] jwt.encode( )가 bytes-str이 아닌 str타입을 리턴 시

개발/Flask 2021. 11. 8. 08:20

jwt.decode('utf-8')에서 AttributeError: 'str' object has no attribute 'decode'. AttributeError: 'str' object has no attribute 'decode'. 와 같은 AtrributeError가 발생하였다. 원인 원인은 PyJWT 모듈의 버전 2.0.0 부터 jwt.encode가 리턴한 token의 타입이 bytes에서 str로 변경되였기 때문이다. 해결 방법 PyJWT의 버전을 2.0.0의 직전 버전인 1.7.1으로 변경하면 임시방편으로 해당 에러는 발생하지 않는다. 추후 2.0.0 버전 이상에서는 decode를 어떻게 하는지 추가할 예정이다. 참고) https://github.com/jazzband/djangorestf..

ValueError: script argument must be unicode. 해결

개발/Flask 2021. 10. 29. 08:20

test.sql 파일을 cursor가 utf-8 포맷으로 지정하지 않아서 unicode가 아니라고 valueError가 발생하였다. #before db_test.cursor().executescript(f.read()) #after db_test.cursor().executescript(f.read().decode('utf-8')) 위와 같이 f.read()뒤에 .decode('utf-8')을 추가하여 해결하였다.

Article Thumbnail
.ini 파일 KeyError 해결 방법

개발/Flask 2021. 10. 28. 08:20

config.ini와 같이 .ini 파일로 데이터베이스 환경변수를 관리하여 unittest를 하던 중, 위와 같이 KeyError가 발생하며 값을 읽어오지 못하는 일이 발생하였다. 원인 원인은 config.ini의 경로를 ../config.ini로 지정하고, basedir를 지정해주지않아서 실행하는 디렉토리에 따라 경로가 달라져 못 읽어오는 것 이었다. 해결방법 config.ini를 불러오는 코드의 윗 줄에 아래와 같이 basedir를 지정해주는 코드를 추가하면 정상적으로 test가 실행됨을 볼 수 있다. basedir = os.path.dirname(os.path.abspath(__file__)) os.chdir(basedir) config = configparser.ConfigParser() conf..

Article Thumbnail
flask db migrate시 psycopg2 image not found 에러 발생시 해결

개발/Flask 2021. 10. 27. 08:20

flask db migrate 커맨드를 입력하였을 때, 위와 같이 psycopg2 관련 import 에러가 발생하며 psycopg2: image not found와 같이 로그가 출력된다. 원인 파이썬과 postgreSQL 연동을 위한 패키지인 psycopg2와 같이 사용되는 psycopg2-binary가 설치되어있지 않아서 발생되는 Import error 였다. 해결방법 pip install psycopg2-binary를 통해 psycopg2-binary를 설치하면 다음과 같이 정상적으로 flask db migrate 커맨드가 작동한다. 참고) https://stackoverflow.com/questions/16407995/psycopg2-image-not-found Psycopg2 image not f..

Article Thumbnail