Python
-
google sheet 내용 python으로 읽고 쓰기프로그래밍 2023. 4. 27. 19:21
우선 관련 패키지를 설치한다. pip install oauth2client pip install gspread 그리고 바로 기존 서비스 키 파일을 사용해서 아래 코드를 돌렸다. from oauth2client.service_account import ServiceAccountCredentials import gspread scope = [ "https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive", ] json_key_path = "./파일이름.json" # JSON Key File Path credential = ServiceAccountCredentials.from_json_keyfile_name(json_key_p..
-
python에서 mysql db 사용하기프로그래밍/python 2022. 9. 13. 15:45
pymysql이 설치가 안되어있다면 pip install pymysql 로 설치를 한다. #pip install pymysql import pymysql conn = pymysql.connect(host='localhost', user='아이디', password='암호', db='디비이름', charset='utf8') 클라이언트의 charset이 제대로 명시되어 있지 않을 경우 한글이 깨질 수 있다. # SQL문 실행 sql = "SELECT * FROM `테이블이름` limit 10" with conn: with conn.cursor() as cur: cur.execute(sql) result = cur.fetchall() for data in result: print(data) print(data..
-
psycopg2.OperationalError: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?프로그래밍/DB 2020. 3. 27. 19:51
postgresql 오류 처리 어느날 서버가 갑자기 다운되어서 재시작을 한 후 매번 잘 돌아가던 python 스크립트에서 갑자기 오류를 내기 시작했다. 참고로 스크립트에서 변경된 사항은 전혀 없었다. Traceback (most recent call last): File "getInfoPost.py", line 379, in conn = pc.connect("dbname=realdbname user=username password=realpass") File "/root/anaconda3/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect conn = _connect(dsn, connection_factory=connection..