Skip to content

Period is up to 2 years 오류가 발생합니다. #269

Open

Description

@ym1018

안녕하세요, 항상 유용하게 사용하고 있습니다. 좋은 라이브러리를 만들어주셔서 감사합니다.

KRX를 지정해서 데이터를 조회하는데 아래와 같이 에러가 발생합니다.

>>> fdr.DataReader('KRX:347850', '2025-11-10', '2025-11-14')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "venv/lib/python3.10/site-packages/FinanceDataReader/data.py", line 98, in DataReader
    return KrxDailyReader(codes, start, end).read()
  File "venv/lib/python3.10/site-packages/FinanceDataReader/krx/data.py", line 241, in read
    df = _krx_stock_price(full_code, from_date=self.start, to_date=self.end)
  File "venv/lib/python3.10/site-packages/FinanceDataReader/krx/data.py", line 139, in _krx_stock_price
    df = _krx_stock_price_2years(full_code, _start, _end)
  File "venv/lib/python3.10/site-packages/FinanceDataReader/krx/data.py", line 112, in _krx_stock_price_2years
    raise ValueError(f'{r.status_code} - {r.reason}' + '(Period is up to 2 years)')
ValueError: 400 - Bad Request(Period is up to 2 years)

2월 10일에 동일하게 조회했을 땐 성공했습니다.
#237 에서 재현 불가 답변을 확인했으나, 금일 오후 내내 해당 오류가 발생하여 일시적인 네트워크 오류는 아닌 것으로 보입니다.
또한 KRX를 지정하지 않고 아래와 같이 조회하는 건 성공합니다.

>>> fdr.DataReader('347850', '2025-11-10', '2025-11-14')

             Open   High    Low  Close   Volume    Change
Date                                                     
2025-11-10  73073  73073  66066  66817  2342709 -0.085613
2025-11-11  66191  72447  63313  70195  2355760  0.050556
2025-11-12  73323  76326  71446  74700  2467316  0.064178
2025-11-13  80000  89100  79700  81800  2311315  0.095047
2025-11-14  79500  86900  78000  85200   920795  0.041565

확인 부탁드리겠습니다.
감사합니다.

Activity

  1. ym1018 commented on Mar 6, 2026

    @ym1018
    Author

    추가적으로 확인한 내용 덧붙입니다. 결론은 #267 과 동일한 원인입니다.

    _krx_stock_price_2years의 다음 위치에서 krx 데이터 조회해오는 동작 확인했습니다.
    현재 r.status_code가 400으로 반환되고 있고, krx 응답 status_code가 200이 아니면 무조건 'Period is up to 2 years' 문구를 출력하고 있어 해당 문제인 것으로 잘못 판단했습니다.

    def _krx_stock_price_2years(full_code, from_date, to_date):
        data = {
            'bld': 'dbms/MDC/STAT/standard/MDCSTAT01701',
            'locale': 'ko_KR',
            'isuCd': full_code,
            'isuCd2': '',
            'strtDd': from_date.strftime("%Y%m%d"),
            'endDd': to_date.strftime("%Y%m%d"),
            'adjStkPrc_check': 'Y',
            'adjStkPrc': 2,
            'share': '1',
            'money': '1',
            'csvxls_isNo': 'false',
        }
    
        url = 'http://data.krx.co.kr/comm/bldAttendant/getJsonData.cmd'
        r = requests.post(url, data, headers=_krx_headers)
        if r.status_code != 200:
            raise ValueError(f'{r.status_code} - {r.reason}' + '(Period is up to 2 years)')
    

    'data.krx.co.kr'의 조회 응답 결과(= r)를 덧붙입니다.

    <Response [400]>
    special variables:
    function variables:
    apparent_encoding: 'ascii'
    connection: <requests.adapters.HTTPAdapter object at 0x784e534827d0>
    content: b'LOGOUT'
    ...
    ok: False
    reason: 'Bad Request'
    status_code: 400
    text: 'LOGOUT'
    url: 'http://data.krx.co.kr/comm/bldAttendant/getJsonData.cmd'
    _content: b'LOGOUT'
    _content_consumed: True
    _next: None
    
  2. FinanceData commented on Mar 11, 2026

    @FinanceData
    Owner

    한국거래소(KRX)가 인증(로그인)을 해야 데이터를 조회할 수 있도록 정책이 변경되었습니다.
    이에 다음과 같이 대응하였습니다.

    https://github.com/FinanceData/FinanceDataReader/wiki/Release-Note-0.9.110

    다만, KRX 개별 종목은 가격 데이터는 아직 지원하지 못하고 있습니다.

    fdr.DataReader('KRX:347850', '2025-11-10', '2025-11-14')
    

    다음과 같이 수정해서 기본 종목코드를 사용하시는 것을 권해 드립니다.

    fdr.DataReader('347850', '2025-11-10', '2025-11-14')
    
                 Open   High    Low  Close   Volume    Change
    Date
    2025-11-10  73073  73073  66066  66817  2342709 -0.085613
    2025-11-11  66191  72447  63313  70195  2355760  0.050556
    2025-11-12  73323  76326  71446  74700  2467316  0.064178
    2025-11-13  80000  89100  79700  81800  2311315  0.095047
    2025-11-14  79500  86900  78000  85200   920795  0.041565
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions