Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 맥북
- SW Expert Academy
- 프로그래머스
- dacon
- gs25
- 캐치카페
- Kaggle
- Git
- 코로나19
- ChatGPT
- 편스토랑 우승상품
- PYTHON
- Baekjoon
- ubuntu
- 데이콘
- 파이썬
- 백준
- github
- 금융문자분석경진대회
- hackerrank
- 자연어처리
- 우분투
- AI 경진대회
- 더현대서울 맛집
- Real or Not? NLP with Disaster Tweets
- 프로그래머스 파이썬
- Docker
- 편스토랑
- programmers
- leetcode
Archives
- Today
- Total
솜씨좋은장씨
[Python] AttributeError: 'NoneType' object has no attribute 'encoding' using pymysql 해결방법 본문
Programming/Python
[Python] AttributeError: 'NoneType' object has no attribute 'encoding' using pymysql 해결방법
솜씨좋은장씨 2021. 10. 26. 14:57728x90
반응형


import pymysql
user = 'user'
password = 'password'
db_host = 'localhost'
db_port = 3306
table_name = 'test_table'
charset = 'utf-8'
db = pymysql.connect(host=db_host, port=db_port, user=user, passwd=password, db=table_name, charset=charset, autocommit=True)
오랜만에 위와 같은 방법으로
pymysql을 활용하여 database에 접근하여 저장되어있는 이미지를 다운로드 받기위해 db 연결을 하려고 하니
AttributeError: 'NoneType' object has no attribute 'encoding' using pymysql
위와 같은 오류가 발생하였습니다.
뭔가 encoding 관련하여 나오는 것을 보니 charset 부분이 문제인가 싶어 stackoverflow 로 질문을 하러 가보니
import pymysql
user = 'user'
password = 'password'
db_host = 'localhost'
db_port = 3306
table_name = 'test_table'
charset = 'utf8'
db = pymysql.connect(host=db_host, port=db_port, user=user, passwd=password, db=table_name, charset=charset, autocommit=True)
역시나 charset 부분에 utf-8 이라고 적어 있는 부분이 문제였고
utf-8 을 - 를 제외한 utf8 로 바꾸어주면 정상없이 연결 되는 것을 볼 수 있었습니다.
👨🏻💻 해결방법 요약
- charset 이 utf-8로 되어있는지 확인해보고 utf-8 이라면 utf8로 변경 후 재시도
읽어주셔서 감사합니다.