josw123 / dart-fss

한국 금융감독원에서 운영하는 다트(Dart) 시스템 크롤링을 위한 라이브러리
https://github.com/josw123/dart-fss
MIT License
319 stars 111 forks source link

#143에 대한 패치 이후 analyze_xbrl()에서 에러가 발생하는 케이스 #145

Closed sukwoo1414 closed 8 months ago

sukwoo1414 commented 8 months ago

143 에 댓글로 추가했다가 다시 이슈 올립니다.

v0.4.5 버전 사용시 다수 종목에서 아래와 같은 오류가 발생합니다. 종목은 035460, 03490, 034810, ... 등입니다. dart에서 보면 해당 종목의 재무제표가 정상적으로 올라와있습니다

Traceback (most recent call last):
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 404, in load_xbrl
    file_path = download_xbrl(path=path, rcept_no=self.rcept_no)
  File "/home/swy/.local/lib/python3.10/site-packages/dart_fss/api/finance/xbrl.py", line 38, in download_xbrl
    resp = request.download(url=url, path=temp, payload=payload)
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/utils/request.py", line 248, in download
    raise FileNotFoundError('target does not exist')
FileNotFoundError: target does not exist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/swyang/test/report.py", line 162, in do_get_fn_from_report
    return analyze_xbrl(report,
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/fs/extract.py", line 1098, in analyze_xbrl
    xbrl = report.xbrl
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 395, in xbrl
    self.load_xbrl()
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 407, in load_xbrl
    xbrl_attached = self._get_xbrl()
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 428, in _get_xbrl
    attached_files = self.find_all(**query)
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 389, in find_all
    dataset[s] = func_set[s]()
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 376, in fn_xbrlviewer
    def fn_xbrlviewer(): return self.xbrlviewer.find_all(**kwargs)
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 312, in xbrlviewer
    self.extract_xbrlviewer()
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/reports.py", line 317, in extract_xbrlviewer
    self._xbrlviewer = XBRLViewer(self.rcp_no, lazy_loading=False)
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/xbrl_viewer.py", line 36, in __init__
    self.load()
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/xbrl_viewer.py", line 109, in load
    self.extract_attached_files()
  File "/home/swyang/.local/lib/python3.10/site-packages/dart_fss/filings/xbrl_viewer.py", line 100, in extract_attached_files
    url_path = tds[1].find('a')['href']

analyze_xbrl() 호출시 사용한 코드는 아래와 같습니다.

from dart_fss.fs.extract import analyze_xbrl
...
def do_get_fn_from_report(report):
    try:
        return analyze_xbrl(report, 
                        separate=True,
                        show_abstract=False,
                        show_class=False,
                        show_concept=True,
                        )
...

재시도해도 동일한 종목에서 동일한 에러가 발생합니다. 제 로컬 문제일까요?

josw123 commented 8 months ago

오늘 중으로 확인해서 답변드리도록 하겠습니다

josw123 commented 8 months ago

안녕하세요.

방금 전에 확인해보니 올려주신 035460, 034810에서는 문제가 발생하지 않는것으로 확인됩니다. (테스트 환경: Python 3.11(windows 11) / Python 3.10(windows 11) / Python 3.11(macos))

image

혹시 추가적인 코드나 환경(virtualenv 같은 가상환경을 사용하셨는지 및 운영체제 등등)을 알려주시면 추가 테스트를 진행해보도록 하겠습니다.

sukwoo1414 commented 8 months ago

사용한 환경은 Ubuntu 22.04, Python3.10이고 가상환경은 사용하지않고 있습니다. 오늘 해보니 며칠전과 에러나는 종목들이 약간 달라졌는데, 여전히 많은 수의 종목에서 위와 같은 에러가 발생하고 있습니다. 제 코드와 댓글로 달아주신 코드로 각각 확인했습니다. 아래는 문제가 발생한 종목코드들의 일부입니다. 000100, 002760, 003090, 003490, 003920, 004430, 004690, 005430, 009410, 010950, 016580, 033630, 033920, 036220, ..

위 종목코드에서 문제가 없다면 제 로컬 문제로 봐야 할 것 같습니다

josw123 commented 8 months ago

확인해보니 동일한 문제가 발생하며, 이유는 아래와 같이 href 링크가 없기 때문입니다. image

수정된 코드는 곧바로 배포하도록 하겠습니다.

josw123 commented 8 months ago

관련 버그를 수정하여 배포(v0.4.7) 하였습니다. 버그리포트 감사합니다.