pycountry
pycountry copied to clipboard
countries.search_fuzzy('Cape Verde') return LookupError
Actually, both Cabo Verde and Cape Verde are used. So, need to add Cape Verde on data
Related (I think the same underlying problem), searching "South Korea", "North Korea", and "Ivory Coast" yields the same error.
This could be partially fixed by splitting up the search string when looking up matches. "Cape Verde" could look through the database matching "cape" and "verde" which would yield a match on "verde". "South Korea" and "North Korea" would yield results for both PRK and KOR, which is at least a step in the right direction. That wouldn't fix "Ivory Coast", though - I think to be able to figure that out, there would need to be a second source of data on top of the ISO data, which is maybe outside the scope of the package.
I think the Author should add the keyword to the database of lib.
+1 encountered the same error on crashing on "Cape Verde" which in the official standard as an alias for Cabo Verde - https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes#CABO
What is actually surprising is that search_fuzzy
throws an exception while get
method doesn't:
print(pycountry.countries.get(name="cape verde")) None print(pycountry.countries.search_fuzzy("cape verde")) LookupError: cape verde
from semantic of 'get' and 'search' I expect the opposite behavior: 'get' throws and 'search' returns None. It's especially strange as search_fuzzy searches for countries with a fuzzy logic so why doesn't it return an empty array if couldn't find anything?
I'm getting the same behavior with "Northern Ireland". It seems that the "space" in the search string is the problem. Some output from my code: Traceback (most recent call last): File "/home/brian/source/PyEyeBoard/src/GUI/QtToolLib.py", line 976, in CreateLogin fuzzy = pycountry.countries.search_fuzzy(country) File "/home/brian/.local/lib/python3.10/site-packages/pycountry/init.py", line 113, in search_fuzzy raise LookupError(query) LookupError: n ire Traceback (most recent call last): File "/home/brian/source/PyEyeBoard/src/GUI/QtToolLib.py", line 976, in CreateLogin fuzzy = pycountry.countries.search_fuzzy(country) File "/home/brian/.local/lib/python3.10/site-packages/pycountry/init.py", line 113, in search_fuzzy raise LookupError(query) LookupError: north ireland Traceback (most recent call last): File "/home/brian/source/PyEyeBoard/src/GUI/QtToolLib.py", line 976, in CreateLogin fuzzy = pycountry.countries.search_fuzzy(country) File "/home/brian/.local/lib/python3.10/site-packages/pycountry/init.py", line 113, in search_fuzzy raise LookupError(query) LookupError: northern ireland SubdivisionHierarchy(code='FJ-N', country_code='FJ', name='Northern', parent_code=None, type='Division') SubdivisionHierarchy(code='GH-NP', country_code='GH', name='Northern', parent_code=None, type='Region') SubdivisionHierarchy(code='PG-NPP', country_code='PG', name='Northern', parent_code=None, type='Province') ...