josw123/dart-fss

fake-useragent 관련 오류 코드 확인 부탁드립니다.

PeachgardenOwner opened this issue · 2 comments

Error occurred during loading data. Trying to use cache server https://fake-useragent.herokuapp.com/browsers/0.1.11
Traceback (most recent call last):
File "C:\Users\andhf\anaconda3\lib\site-packages\fake_useragent\utils.py", line 154, in load
for item in get_browsers(verify_ssl=verify_ssl):
File "C:\Users\andhf\anaconda3\lib\site-packages\fake_useragent\utils.py", line 99, in get_browsers
html = html.split('

')[1]
IndexError: list index out of range

가끔 해당 오류가 일어나더라도 다시 읽으면 다연스럽게 로딩되던 것이 이제는 완전히 죽어버렸네요.

html 코드 오류로 인하여 발생되는 코드라 하는데 임시방편으로 제시된

from fake_useragent import UserAgent

ua = UserAgent(use_cache_server=True)
ua.random

방법을 써도 해결되는것이 아니어서 제작자분이 직접 손을 봐주셔야 할듯합니다. 감사합니다.

이하 오류코드 전문입니다.

Error occurred during loading data. Trying to use cache server https://fake-useragent.herokuapp.com/browsers/0.1.11
Traceback (most recent call last):
File "C:\Users\andhf\anaconda3\lib\site-packages\fake_useragent\utils.py", line 154, in load
for item in get_browsers(verify_ssl=verify_ssl):
File "C:\Users\andhf\anaconda3\lib\site-packages\fake_useragent\utils.py", line 99, in get_browsers
html = html.split('

')[1]
IndexError: list index out of range

IndexError Traceback (most recent call last)
~\anaconda3\lib\site-packages\fake_useragent\utils.py in load(use_cache_server, verify_ssl)
153 try:
--> 154 for item in get_browsers(verify_ssl=verify_ssl):
155 browser, percent = item

~\anaconda3\lib\site-packages\fake_useragent\utils.py in get_browsers(verify_ssl)
98 html = html.decode('utf-8')
---> 99 html = html.split('

')[1]
100 html = html.split('
')[0]

IndexError: list index out of range

During handling of the above exception, another exception occurred:

HTTPError Traceback (most recent call last)
~\anaconda3\lib\site-packages\fake_useragent\utils.py in get(url, verify_ssl)
63
---> 64 with contextlib.closing(urlopen(
65 request,

~\anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
213 opener = _opener
--> 214 return opener.open(url, data, timeout)
215

~\anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
522 meth = getattr(processor, meth_name)
--> 523 response = meth(req, response)
524

~\anaconda3\lib\urllib\request.py in http_response(self, request, response)
631 if not (200 <= code < 300):
--> 632 response = self.parent.error(
633 'http', request, response, code, msg, hdrs)

~\anaconda3\lib\urllib\request.py in error(self, proto, *args)
560 args = (dict, 'default', 'http_error_default') + orig_args
--> 561 return self._call_chain(*args)
562

~\anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
493 func = getattr(handler, meth_name)
--> 494 result = func(*args)
495 if result is not None:

~\anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
640 def http_error_default(self, req, fp, code, msg, hdrs):
--> 641 raise HTTPError(req.full_url, code, msg, hdrs, fp)
642

HTTPError: HTTP Error 503: Service Unavailable

During handling of the above exception, another exception occurred:

FakeUserAgentError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_24572/1674880822.py in
1 # Dart-fss 라이브러리 불러오기
----> 2 import dart_fss as dart
3
4
5 from fake_useragent import UserAgent

~\anaconda3\lib\site-packages\dart_fss_init_.py in
1 # -- coding: utf-8 --
----> 2 from dart_fss import api, auth, corp, errors, filings, fs, utils, xbrl
3 from dart_fss.auth import set_api_key, get_api_key
4 from dart_fss.corp import get_corp_list
5 from dart_fss.filings import search

~\anaconda3\lib\site-packages\dart_fss\api_init_.py in
1 # -- coding: utf-8 --
----> 2 from dart_fss.api import filings, finance, info, shareholder, market
3
4
5 all = ['filings', 'finance', 'info', 'shareholder', 'market']

~\anaconda3\lib\site-packages\dart_fss\api\filings_init_.py in
----> 1 from .company import get_corp_info
2 from .corp_code import get_corp_code
3 from .document import download_document
4 from .search_filings import search_filings
5

~\anaconda3\lib\site-packages\dart_fss\api\filings\company.py in
1 # -- coding: utf-8 --
----> 2 from ..helper import api_request
3
4
5 def get_corp_info(corp_code: str):

~\anaconda3\lib\site-packages\dart_fss\api\helper.py in
3
4 from urllib.parse import urljoin
----> 5 from dart_fss.auth import get_api_key
6 from dart_fss.utils import request
7 from dart_fss.errors import check_status

~\anaconda3\lib\site-packages\dart_fss\auth_init_.py in
1 # -- coding: utf-8 --
----> 2 from dart_fss.auth.auth import set_api_key, get_api_key
3
4 all = ['set_api_key', 'get_api_key']

~\anaconda3\lib\site-packages\dart_fss\auth\auth.py in
2 import os
3
----> 4 from dart_fss.utils import Singleton, request
5 from dart_fss.errors import check_status
6

~\anaconda3\lib\site-packages\dart_fss\utils_init_.py in
4 from dart_fss.utils.file import unzip, xml_to_dict, search_file, create_folder, get_cache_folder
5 from dart_fss.utils.notebook import dict_to_html, is_notebook
----> 6 from dart_fss.utils.request import get_user_agent, query_to_regex, request
7 from dart_fss.utils.singleton import Singleton
8 from dart_fss.utils.spinner import Spinner, spinner_enable

~\anaconda3\lib\site-packages\dart_fss\utils\request.py in
273
274 # Request object
--> 275 request = Request()

~\anaconda3\lib\site-packages\dart_fss\utils\singleton.py in call(cls, *args, **kwargs)
6 def call(cls, *args, **kwargs):
7 if cls not in cls._instances:
----> 8 cls._instances[cls] = super(Singleton, cls).call(*args, **kwargs)
9 return cls._instances[cls]

~\anaconda3\lib\site-packages\dart_fss\utils\request.py in init(self)
60 def init(self):
61 self.s = requests.Session()
---> 62 self.update_user_agent()
63 # 분당 1000회 이상 자체적으로 24시간 IP차단
64 # IP 차단 방지 위해 delay 0.1s -> 0.2s

~\anaconda3\lib\site-packages\dart_fss\utils\request.py in update_user_agent(self, force)
78 user_agent = str(agent)
79 else:
---> 80 user_agent = get_user_agent()
81 self.s.headers.update({'user-agent': user_agent})
82

~\anaconda3\lib\site-packages\dart_fss\utils\cache.py in wrapped(*args, **kwargs)
28 key = tuple(args), frozenset(kwargs.items())
29 if key not in cached or now - cached[key][0] > ttl:
---> 30 value = func(*args, **kwargs)
31 cached[key] = (now, value)
32 return cached[key][1]

~\anaconda3\lib\site-packages\dart_fss\utils\request.py in get_user_agent()
16 user-agent
17 """
---> 18 ua = UserAgent()
19 agent = ua.chrome
20 return str(agent)

~\anaconda3\lib\site-packages\fake_useragent\fake.py in init(self, cache, use_cache_server, path, fallback, verify_ssl, safe_attrs)
67 self.data_browsers = {}
68
---> 69 self.load()
70
71 def load(self):

~\anaconda3\lib\site-packages\fake_useragent\fake.py in load(self)
73 with self.load.lock:
74 if self.cache:
---> 75 self.data = load_cached(
76 self.path,
77 use_cache_server=self.use_cache_server,

~\anaconda3\lib\site-packages\fake_useragent\utils.py in load_cached(path, use_cache_server, verify_ssl)
248 def load_cached(path, use_cache_server=True, verify_ssl=True):
249 if not exist(path):
--> 250 update(path, use_cache_server=use_cache_server, verify_ssl=verify_ssl)
251
252 return read(path)

~\anaconda3\lib\site-packages\fake_useragent\utils.py in update(path, use_cache_server, verify_ssl)
243 rm(path)
244
--> 245 write(path, load(use_cache_server=use_cache_server, verify_ssl=verify_ssl))
246
247

~\anaconda3\lib\site-packages\fake_useragent\utils.py in load(use_cache_server, verify_ssl)
185 )
186 try:
--> 187 ret = json.loads(get(
188 settings.CACHE_SERVER,
189 verify_ssl=verify_ssl,

~\anaconda3\lib\site-packages\fake_useragent\utils.py in get(url, verify_ssl)
82
83 if attempt == settings.HTTP_RETRIES:
---> 84 raise FakeUserAgentError('Maximum amount of retries reached')
85 else:
86 logger.debug(

FakeUserAgentError: Maximum amount of retries reached

안녕하세요.

fake-useragent v1.0 대응 및 arelle 최신 버전 대응을 위한 dart-fss v0.4.0 배포가 있었습니다. 이를 통해 올려주신 문제는 해결하였으니 아래와 같이 dart-fss 라이브러리를 업데이트해서 시도해보시기 바랍니다.

pip install dart-fss -U

만약 업데이트 후에도 문제가 발생하시면 추가로 관련 사항을 남겨주시면 감사하겠습니다.

안녕하세요.

문제가 해결되긴 했습니다.

추후 다시 발생된다면 문의드리도록 하겠습니다.

감사합니다.