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

etf.info Raising error '"dictionary update sequence element #4 has length 0; 2 is required" #21

Open
jmakris1 opened this issue Jul 1, 2024 · 1 comment

Comments

@jmakris1
Copy link

jmakris1 commented Jul 1, 2024

The error I'm experiencing is below. Any call I make to the .info method produces the error, but other methods are working just as they should. It has something to do with the library retrieving and converting data into dictionary format. Any help with this would be appreciated.

Traceback (most recent call last):
File "/Users/yourName/Downloads/ETF_Project/env/lib/python3.12/site-packages/etfpy/etf.py", line 61, in info
return self._basic_info()
^^^^^^^^^^^^^^^^^^
File "/Users/yourName/Downloads/ETF_Project/env/lib/python3.12/site-packages/etfpy/client/etf_client.py", line 288, in _basic_info
basic_information.update(self._profile_container())
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/yourName/Downloads/ETF_Project/env/lib/python3.12/site-packages/etfpy/client/etf_client.py", line 101, in _profile_container
return dict(results)
^^^^^^^^^^^^^
ValueError: dictionary update sequence element #4 has length 0; 2 is required

@jmakris1
Copy link
Author

jmakris1 commented Jul 2, 2024

I have found the fix to the above. In etf_client.py, within the _profile_container function I added a condition to ensure the record has length of 2 before appending it to 'results'.

Updated code below:

def _profile_container(self) -> dict:
    profile_container = self._soup.find("div", {"class": "profile-container"})
    results: List[Tuple] = []
    for row in profile_container.find_all("div", class_="row"):
        spans = row.find_all("span")
        record = _handle_spans(spans)
        if record is None or len(record) != 2:
            continue
        results.append(record)
    return dict(results)

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

1 participant