FinanceData / FinanceDataReader

Financial data reader
1.1k stars 357 forks source link

Update listing.py #189

Closed iburn78 closed 8 months ago

iburn78 commented 9 months ago

An error keeps occurring when using this function as it is. By adding encoding='euc-kr' it seems working.

ntopia commented 6 months ago

혹시 이 PR이 왜 닫혔는지 알려주실 수 있을까요? 저도 동일한 오류를 겪고 있고, 이 패치를 적용하면 해결됩니다. 반영이 되었으면 하는 바람을 담아 코멘트 남겨봅니다.

코드:

import FinanceDataReader as fdr
stocks = fdr.StockListing('KRX-DESC').head(5)
print(stocks)

발생 에러:

Traceback (most recent call last):
  File "<...>/test.py", line 2, in <module>
    stocks = fdr.StockListing('KRX-DESC').head(5)
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/FinanceDataReader/data.py", line 139, in StockListing
    return KrxStockListing(market).read()
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/FinanceDataReader/krx/listing.py", line 65, in read
    df_listing = pd.read_html(url, header=0)[0]
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pandas/io/html.py", line 1245, in read_html
    return _parse(
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pandas/io/html.py", line 1008, in _parse
    raise retained
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pandas/io/html.py", line 988, in _parse
    tables = p.parse_tables()
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pandas/io/html.py", line 248, in parse_tables
    tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pandas/io/html.py", line 658, in _build_doc
    bdoc = self._setup_build_doc()
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pandas/io/html.py", line 650, in _setup_build_doc
    raw_text = _read(self.io, self.encoding, self.storage_options)
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pandas/io/html.py", line 145, in _read
    text = handles.handle.read()
  File "<...>/.pyenv/versions/3.10.13/lib/python3.10/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 144: invalid start byte

사용 중인 패키지:

beautifulsoup4==4.12.2
certifi==2023.11.17
charset-normalizer==3.3.2
dnspython==2.4.2
finance-datareader==0.9.66
html5lib==1.1
idna==3.6
lxml==5.0.0
numpy==1.26.2
packaging==23.2
pandas==2.1.4
plotly==5.18.0
pymongo==4.6.1
python-dateutil==2.8.2
pytz==2023.3.post1
requests==2.31.0
requests-file==1.5.1
six==1.16.0
soupsieve==2.5
tenacity==8.2.3
tqdm==4.66.1
tzdata==2023.4
urllib3==2.1.0
webencodings==0.5.1