Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json.decoder.JSONDecodeError: Expecting value: line 15 column 3 (char 33) #216

Open
kunsungwoo opened this issue Jul 5, 2024 · 10 comments

Comments

@kunsungwoo
Copy link

kunsungwoo commented Jul 5, 2024

line 52, in load_data
df = fdr.StockListing(market)
line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 15 column 3 (char 33)

NASDAQ works, but KRX, KOSDAQ, and KOSPI have problems.
What is the problem??

@hogisim314
Copy link

me too

@jinwone-choi
Copy link

저도 그러네요! 수정 부탁드립니다.

@jackmappotion
Copy link
Contributor

jackmappotion commented Jul 8, 2024

확인 시점 : 2024-07-08 09:01:06
오류 위치 : https://github.com/FinanceData/FinanceDataReader/blob/master/krx/listing.py

class KrxMarcapListing:
    def __init__(self, market):
        self.market = market

    def read(self):
        url = 'http://data.krx.co.kr/comm/bldAttendant/executeForResourceBundle.cmd?baseName=krx.mdc.i18n.component&key=B128.bld'
        j = json.loads(requests.get(url).text)
        date_str = j['result']['output'][0]['max_work_dt']

# 여기서 json decode 오류 발생
url = 'http://data.krx.co.kr/comm/bldAttendant/executeForResourceBundle.cmd?baseName=krx.mdc.i18n.component&key=B128.bld'
 j = json.loads(requests.get(url).text)
-- requests.get(url).text

<div class="content">
  <p>
    <span>서비스 제공 불가능</span>
    일시적 접근 불안정으로 인하여 서비스가 원활하지 않습니다.<br>
    이와 관련해서 문의사항이 있으시면 시스템 담당자에게 연락해 주시기 바랍니다.
  </p>
</div>

@QuantKang
Copy link

7월 1일에도 발생했던 오류인데, 그 때는 얼마 지나지 않아서 다시 제대로 동작했었습니다. 이번에는 좀 오래가네요. #215

@bahamute00
Copy link

krx 쪽만 문제 가 있어 보이네요.
저역시 동일한 문제가....

@iburn78
Copy link

iburn78 commented Jul 8, 2024

FDR이 KRX에서 Data 읽어 오는것이 Post Request, Json read 방식인데... 이걸 KRX에서 그냥 닫아버린거 아닐까 하는 의심이 드네요.

KRX에서 별도의 (허접한) OpenAPI를 제공하는데 이 OpenAPI로 코드 수정이 들어가야 할지도 모르겠네요...

@KINOSS1
Copy link

KINOSS1 commented Jul 8, 2024

pykrx 도 유사한 오류가 발생하는 것 같은데, 아래와 같이 수정하면 해결이 된다고 하네요.

sharebook-kr/pykrx#185

https://github.com/sharebook-kr/pykrx/pull/188/files

@kunsungwoo
Copy link
Author

일단은 requests\utils.py 의
def default_headers():
"""
:rtype: requests.structures.CaseInsensitiveDict
"""
return CaseInsensitiveDict(
{
#"User-Agent": default_user_agent(),
"User-Agent": "Mozilla/5.0", "Referer": "http://data.krx.co.kr/",
"Accept-Encoding": DEFAULT_ACCEPT_ENCODING,
"Accept": "/",
"Connection": "keep-alive",
}

)
로 수정하면 작동은하네요.
"User-Agent": default_user_agent(), -> "User-Agent": "Mozilla/5.0", "Referer": "http://data.krx.co.kr/",
이걸 이렇게 수정하면 작동은합니다.

@FinanceData
Copy link
Owner

FinanceData commented Jul 9, 2024

KRX 요청 header에 Referer가 "필수"로 바뀌었고, 이에 대응하여 업데이트 하였습니다.

업데이트하여 사용하시면 되겠습니다.

pip install -U finance-datareader

첨언을 드리자면,
확인 할 수 없지만 KRX 측에서 일부러 크롤링을 막기위해 적극적으로 조치한 것으로 보이지는 않구요.
아마 보안 장비의 설정을 업데이트 하면서 header에 대한 필수 요구사항이 추가된 것으로 보입니다.

많은 관심과 도움 감사합니다.

@FinanceData
Copy link
Owner

헤더 관련 내용과 함께 KRX 관련한 큰 이슈들이 FIX 되었습니다.

보다 자세한 내용은:
https://github.com/FinanceData/FinanceDataReader/wiki/Release-Note-0.9.92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants