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

AttributeError: 'NoneType' object has no attribute 'f_locals' #9

Closed
hoanghn418 opened this issue Nov 2, 2024 · 2 comments
Closed

Comments

@hoanghn418
Copy link

hoanghn418 commented Nov 2, 2024

I get a error when test function download_company_concepts.
Snipcode:

from datamule import Downloader

downloader = Downloader()
downloader.download_company_concepts()

Error logs:

Failed to download: 404, message='Not Found', url='https://data.sec.gov/api/xbrl/companyfacts/CIK0001169034.json'
Downloading files:  79%|█████████████████████████████████████████████████████▉              | 8072/10167 [1:02:09<03:40,  9.50it/s]
Failed to download: 404, message='Not Found', url='https://data.sec.gov/api/xbrl/companyfacts/CIK0001779303.json'
Downloading files:  79%|██████████████████████████████████████████████████████              | 8082/10167 [1:02:10<03:04, 11.27it/s]
Failed to download: 404, message='Not Found', url='https://data.sec.gov/api/xbrl/companyfacts/CIK0001227862.json'
Downloading files:  80%|██████████████████████████████████████████████████████              | 8086/10167 [1:02:10<03:45,  9.25it/s]Error downloading https://data.sec.gov/api/xbrl/companyfacts/CIK0001278752.json: https://data.sec.gov/api/xbrl/companyfacts/CIK0001278752.json

Rate limited for https://data.sec.gov/api/xbrl/companyfacts/CIK0001278752.json. Will retry after 601 seconds.

Rate limit hit. Sleeping for 601 seconds before retrying.
Downloading files:  80%|██████████████████████████████████████████████████████              | 8086/10167 [1:46:00<27:17,  1.27it/s]
Traceback (most recent call last):
  File "/datamule-python/datamule/../examples/download_company_concepts_for_all_companies.py", line 5, in <module>
    downloader.download_company_concepts()
  File "/datamule-python/.venv/lib/python3.12/site-packages/datamule-0.376-py3.12.egg/datamule/downloader/sec_downloader.py", line 493, in download_company_concepts
    self.run_download_urls(urls=urls, filenames=filenames, output_dir=output_dir)
  File "/datamule-python/.venv/lib/python3.12/site-packages/datamule-0.376-py3.12.egg/datamule/downloader/sec_downloader.py", line 198, in run_download_urls
    return asyncio.run(self._download_urls(urls, filenames, output_dir))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/datamule-python/.venv/lib/python3.12/site-packages/datamule-0.376-py3.12.egg/datamule/downloader/sec_downloader.py", line 188, in _download_urls
    urls = [task.get_coro().cr_frame.f_locals['url'] for task in pending]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'f_locals'

How about includes a check to ensure task.get_coro().cr_frame is not None before accessing f_locals?

urls = [task.get_coro().cr_frame.f_locals['url'] for task in pending if task.get_coro().cr_frame is not None]
@340cruz
Copy link

340cruz commented Nov 2, 2024 via email

@john-friedman
Copy link
Owner

Hi @340cruz, very helpful. The Failed to download print statement is because of missing information - not a real error. I haven't fixed it yet as it would require time that I'd rather spend working on the parsers.

@hoanghn418 The error stopping your code from running is that the rate limit was triggered, and the downloader failed to handle it correctly. This may be because you opened a sec.gov url in your browser which pushed the requests/second over the maximum, and then the downloader incorrectly handled the rate limit error.

Workaround:

downloader.set_limiter('www.sec.gov', 5)
downloader.set_limiter('efts.sec.gov', 5)

I'll look into updating the downloader to be more robust with rate-limits. Note: I'm working on something that will allow me to move away from downloading using the SEC as rate limits + lack of metadata is currently the most requested feature.

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

3 participants