FastAPI uvicorn으로 PostgreSQL 접속할 때 설정의 URL 문자열은 보통 아래와 같다.
| postgresql+asyncpg://[ID]:[PASSWORD]@[IP_ADDRESS]:[PORT]/[DATABASE-NAME] |
(예) 로컬호스트의 testdb 데이터베이스에 postgre 계정과 passw0rd 비밀번호로 접근하는 경우:
| postgresql+asyncpg://postgre:passw0rd@localhost:5432/testdb |
그런데 비밀번호에 '@' 특수문자를 사용할 경우, '@'를 그대로 쓰면 문제가 발생한다.
| postgresql+asyncpg://postgre:p@ssw0rd@localhost:5432/testdb |
이러면 첫번째로 나오는 '@'를 구분자로 쓰면서 URL이 "ssw0rd@localhost"가 되면서, DB 접속 에러가 발생한다.
File "uvloop/loop.pyx", line 1982, in create_connection
socket.gaierror: [Errno -2] Name or service not known
ERROR: Application startup failed. Exiting.
*해결 방법
암호 문자열에 포함되는 '@' 문자를 %40으로 대체한다.
| postgresql+asyncpg://postgre:p%40ssw0rd@localhost:5432/testdb |
'Development' 카테고리의 다른 글
| if-else vs. if-return: 코딩 스타일과 가독성의 차이 (1) | 2017.03.28 |
|---|---|
| Visual Studio .NET / 기발한 Visual Studio 2005 텍스트 에디팅 단축키 (0) | 2009.06.23 |