python-sec
python-sec copied to clipboard
ValueError: Unrecognised argument(s): encoding
import sys
sys.path
sys.path.append('/home/oonisim/home/repository/git/oonisim/finance/alexreed/python-sec/')
from pprint import pprint
from edgar.client import EdgarClient
from edgar.enums import StateCodes
from edgar.enums import CountryCodes
from edgar.enums import StandardIndustrialClassificationCodes
# Initialize the Edgar Client
edgar_client = EdgarClient()
# Initialize the Company Services.
company_services = edgar_client.companies()
# Grab all the companies that are based in Texas.
pprint(company_services.get_companies_by_state(state_code='TX'))
# Grab all the companies that are based in Australia, same logic here with the Enums.
pprint(
company_services.get_companies_by_country(
country_code=CountryCodes.AUSTRALIA
)
)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_7643/255480336.py in <module>
6
7 # Initialize the Edgar Client
----> 8 edgar_client = EdgarClient()
9
10 # Initialize the Company Services.
~/home/repository/git/oonisim/finance/alexreed/python-sec/edgar/client.py in __init__(self)
24 """
25
---> 26 self.edgar_session = EdgarSession(client=self)
27
28 def __repr__(self) -> str:
~/home/repository/git/oonisim/finance/alexreed/python-sec/edgar/session.py in __init__(self, client)
45 pathlib.Path('logs/sec_api_log.log').touch()
46
---> 47 logging.basicConfig(
48 filename="logs/sec_api_log.log",
49 level=logging.INFO,
/usr/lib/python3.8/logging/__init__.py in basicConfig(**kwargs)
2007 if kwargs:
2008 keys = ', '.join(kwargs.keys())
-> 2009 raise ValueError('Unrecognised argument(s): %s' % keys)
2010 finally:
2011 _releaseLock()
ValueError: Unrecognised argument(s): encoding
Try upgrading the package first and let me know if that resolves this issue. If not I'll spend some more time looking into this.
Hi @areed1192, unfortunately the issue still persists with the latest version.
Git pull done and the version is at 0.1.6 in /home/oonisim/home/repository/git/oonisim/finance/alexreed/python-sec/.
commit e082df20246e6a4be2972aaaaee588521021fe32 (HEAD -> master, tag: 0.1.6, origin/master, origin/HEAD)
Author: Alex Reed <[email protected]>
Date: Sat Oct 23 10:39:53 2021 -0700
Remove find_dir, prep for 0.1.6
Error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_42560/4170079792.py in <module>
10
11 # Initialize the Edgar Client
---> 12 edgar_client = EdgarClient()
13
14 # Initialize the Company Services.
~/venv/finance/lib/python3.8/site-packages/edgar/client.py in __init__(self)
33 """
34
---> 35 self.edgar_session = EdgarSession(client=self)
36
37 def __repr__(self) -> str:
~/venv/finance/lib/python3.8/site-packages/edgar/session.py in __init__(self, client)
45 pathlib.Path('logs/sec_api_log.log').touch()
46
---> 47 logging.basicConfig(
48 filename="logs/sec_api_log.log",
49 level=logging.INFO,
/usr/lib/python3.8/logging/__init__.py in basicConfig(**kwargs)
2007 if kwargs:
2008 keys = ', '.join(kwargs.keys())
-> 2009 raise ValueError('Unrecognised argument(s): %s' % keys)
2010 finally:
2011 _releaseLock()
ValueError: Unrecognised argument(s): encoding
Found the issue, in python 3.8 the logging.basicConfig() function doesn't allow for the encoding argument. Hence why you were getting the error. It looks like they added it in python 3.9, so what I did is added a check for the user's python version. If it's below 3.9 it won't add the encoding argument.
I am having this issue as well. The library's setup.py says it supports python 3.7 and up.
I wonder if you would reconsider how you do logging in the library? The library makes assumptions about how the user wants to log, and it goes against best practices recommended by the Python core team. In general, library loggers should only use the NullHandler to let the user decide on the format and location to log. Let me know if you have any questions regarding this, more than willing to clarify further.
.
I have a WIP of this idea here: https://github.com/areed1192/python-sec/pull/9
It isn't ready yet, but it demonstrates the idea.