INVESTAR / StockAnalysisInPython

459 stars 413 forks source link

chap 5 질문있습니다 (mysql 관련) #40

Open Eom-taeseon opened 3 years ago

Eom-taeseon commented 3 years ago

5.1.2 네이버 금융 데이터로 시세 데이터베이스 구축하기에서

mk = Analyzer.MarketDB()
df = mk.get_daily_price('005930', '2017-07-10', '2018-06-30')

이러한 코드를 쳤을 때


OperationalError Traceback (most recent call last)

in ----> 1 mk = Analyzer.MarketDB() 2 df = mk.get_daily_price('005930', '2017-07-10', '2018-06-30') ~\Desktop\파이썬 증권 데이터 분석\chap5\Investar\Analyzer.py in __init__(self) 8 def __init__(self): 9 """생성자: MariaDB 연결 및 종목코드 딕셔너리 생성""" ---> 10 self.conn = pymysql.connect(host='localhost', user='root', 11 password='snake.land.', db='INVESTAR', charset='utf8') 12 self.codes = {} ~\anaconda3\lib\site-packages\pymysql\connections.py in __init__(self, user, password, host, database, unix_socket, port, charset, sql_mode, read_default_file, conv, use_unicode, client_flag, cursorclass, init_command, connect_timeout, read_default_group, autocommit, local_infile, max_allowed_packet, defer_connect, auth_plugin_map, read_timeout, write_timeout, bind_address, binary_prefix, program_name, server_public_key, ssl, ssl_ca, ssl_cert, ssl_disabled, ssl_key, ssl_verify_cert, ssl_verify_identity, compress, named_pipe, passwd, db) 351 self._sock = None 352 else: --> 353 self.connect() 354 355 def __enter__(self): ~\anaconda3\lib\site-packages\pymysql\connections.py in connect(self, sock) 631 632 self._get_server_information() --> 633 self._request_authentication() 634 635 if self.sql_mode is not None: ~\anaconda3\lib\site-packages\pymysql\connections.py in _request_authentication(self) 930 # https://dev.mysql.com/doc/internals/en/successful-authentication.html 931 if self._auth_plugin_name == "caching_sha2_password": --> 932 auth_packet = _auth.caching_sha2_password_auth(self, auth_packet) 933 elif self._auth_plugin_name == "sha256_password": 934 auth_packet = _auth.sha256_password_auth(self, auth_packet) ~\anaconda3\lib\site-packages\pymysql\_auth.py in caching_sha2_password_auth(conn, pkt) 264 265 data = sha2_rsa_encrypt(conn.password, conn.salt, conn.server_public_key) --> 266 pkt = _roundtrip(conn, data) ~\anaconda3\lib\site-packages\pymysql\_auth.py in _roundtrip(conn, send_data) 118 def _roundtrip(conn, send_data): 119 conn.write_packet(send_data) --> 120 pkt = conn._read_packet() 121 pkt.check_error() 122 return pkt ~\anaconda3\lib\site-packages\pymysql\connections.py in _read_packet(self, packet_type) 723 if self._result is not None and self._result.unbuffered_active is True: 724 self._result.unbuffered_active = False --> 725 packet.raise_for_error() 726 return packet 727 ~\anaconda3\lib\site-packages\pymysql\protocol.py in raise_for_error(self) 219 if DEBUG: 220 print("errno =", errno) --> 221 err.raise_mysql_exception(self._data) 222 223 def dump(self): ~\anaconda3\lib\site-packages\pymysql\err.py in raise_mysql_exception(data) 141 if errorclass is None: 142 errorclass = InternalError if errno < 1000 else OperationalError --> 143 raise errorclass(errno, errval) OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

이러한 에러가 발생합니다.

찾아보니 MySQL 비밀번호와 관련한 에러인 것 같은데 해결 방법을 도저히 모르겠습니다 ㅠㅠ

INVESTAR commented 3 years ago

Anayzer.py와 MarketDB.py에는 마리아디비에 접속하는 코드가 있습니다. 해당 코드에서 패스워드는 실제로 독자님이 구축하신 마리아디비의 비밀번호를 입력해 주셔야 합니다.

self.conn = pymysql.connect(host='localhost', user='root', password='myPa$$word', db='INVESTAR', charset='utf8')

Analyzer.py

class MarketDB:
    def __init__(self):
        """생성자: MariaDB 연결 및 종목코드 딕셔너리 생성"""
        self.conn = pymysql.connect(host='localhost', user='root', 
            password='myPa$$word', db='INVESTAR', charset='utf8')
        self.codes = {}
        self.get_comp_info()

MarketDB.py

class MarketDB:
    def __init__(self):
        """생성자: MariaDB 연결 및 종목코드 딕셔너리 생성"""
        self.conn = pymysql.connect(host='localhost', user='root', password='myPa$$word', db='INVESTAR', charset='utf8')
        self.codes = dict()
        self.getCompanyInfo()