Skip to content

Fix KeyError: 'container' when scraping cover photo metadata - #607

Open
mikotokuroko wants to merge 1 commit into
mxrch:masterfrom
mikotokuroko:patch-1
Open

Fix KeyError: 'container' when scraping cover photo metadata#607
mikotokuroko wants to merge 1 commit into
mxrch:masterfrom
mikotokuroko:patch-1

Conversation

@mikotokuroko

Copy link
Copy Markdown

Problem

ghunt email <address> --json ... crashes with a KeyError: 'container' during the person scrape step:

File "ghunt/parsers/people.py", line 164, in _scrape
    self.coverPhotos[cover_photo_data["metadata"]["container"]] = person_cover_photo
KeyError: 'container'

This happens in _scrape() when Google's People API returns cover photo metadata without a container field. The field isn't always present depending on the account's privacy settings / whether a custom cover photo is set, so indexing into it directly with [...] crashes instead of degrading gracefully.


Fix

Use .get() to safely check for the container key, and skip adding the cover photo entry if it's missing rather than crashing the whole lookup:

container = cover_photo_data["metadata"].get("container")
if container is not None:
    self.coverPhotos[container] = person_cover_photo

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

Successfully merging this pull request may close these issues.

1 participant