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

Handelsregister demo code returns error #37

Open
auchtetraborat opened this issue Oct 9, 2021 · 2 comments
Open

Handelsregister demo code returns error #37

auchtetraborat opened this issue Oct 9, 2021 · 2 comments

Comments

@auchtetraborat
Copy link
Contributor

Running the demo code in the README.md for the Handelsregister module returns an error.

How to reproduce:

>>> from deutschland import Bundesanzeiger
>>> from deutschland import Handelsregister
>>> hr = Handelsregister()
>>> hr.search(keywords="Deutsche Bahn Aktiengesellschaft")

Expected result:

  • Handelsregister infos to be retrieved and stored in 'hr' object.

What I got instead:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/Dokumente/bundesapi/test_bundesapi_2/env/lib/python3.9/site-packages/deutschland/handelsregister/handelsregister.py", line 138, in search
    return self.search_with_raw_params(params)
  File "/home/xxx/Dokumente/bundesapi/test_bundesapi_2/env/lib/python3.9/site-packages/deutschland/handelsregister/handelsregister.py", line 215, in search_with_raw_params
    return self.__find_entries(soup)
  File "/home/xxx/Dokumente/bundesapi/test_bundesapi_2/env/lib/python3.9/site-packages/deutschland/handelsregister/handelsregister.py", line 242, in __find_entries
    data = self.__extract_history(tr)
  File "/home/xxx/Dokumente/bundesapi/test_bundesapi_2/env/lib/python3.9/site-packages/deutschland/handelsregister/handelsregister.py", line 276, in __extract_history
    [position, historical_name] = tds[1].text.strip().split(".) ", 1)
ValueError: not enough values to unpack (expected 2, got 1)

My env:

  • Ubuntu 20.04, venv with 3.9.6 and pip 21.2.4
@auchtetraborat
Copy link
Contributor Author

The error appears to be caused by the websites data being in a different format then expected.

[position, historical_name] = tds[1].text.strip().split(".) ", 1)

tds[1] usually looks something like: "1.) xyz GmbH"
Before the error occurs, tds[1] is "-Deutsche Kreditbank Aktiengesellschaft Niederlassung Berlin ", containing no '.)'.

A similar error will appear in the next line:

historical_location = tds[2].text.strip().split(".) ", 1)[1]

Usually: " 1.) Bad Elster "
New format: "Berlin "

The data can also be viewed here: https://www.handelsregister.de/rp_web/result.do?Page=4

Unfortunatly, I dont know enough about the Handelsregister module's logic to proberly add input handling for this format.

@kiranmusze
Copy link

kiranmusze commented Nov 23, 2021

I found the bug. It is in the method def __extract_history(self, row): in line 203 in deutschland/handelsregister/registrations.py

Replace these lines:

[position, historical_name] = tds[1].text.strip().split(".) ", 1)
historical_location = tds[2].text.strip().split(".) ", 1)[1]

with these ones:

position = tds[1].text.strip().split(".) ", 1)[0]
historical_name = tds[1].text.strip().split(".) ", 1)[1:]
historical_location = tds[2].text.strip().split(".) ", 1)[1:]

Now it should be working. Hope this helps.

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

2 participants