Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

API Error on Import #147

Open
lazarust opened this issue Nov 5, 2021 · 3 comments
Open

API Error on Import #147

lazarust opened this issue Nov 5, 2021 · 3 comments

Comments

@lazarust
Copy link

lazarust commented Nov 5, 2021

Is there a reason the API is pinged when importing the library? It seems a little weird and has caused some issues for me when running tests. Thanks!

@ljwolf
Copy link
Member

ljwolf commented Nov 5, 2021

The library fetches the current copy of the metadata upon import, and uses this to structure the API. it's part of the design: we don't want to mirror or maintain duplicates of the main API metadata endpoints.

I suppose, strictly speaking, it doesn't have to be fetched on import, but rather could be pushed down into the first (if any) call to explorer.available() & cached once fetched.

Happy to merge any contribution to do this!

@lazarust
Copy link
Author

@ljwolf Could you point me to where that initial API fetch is? I'm having trouble finding it. Thanks 👍🏽

@ronnie-llamado
Copy link
Member

@lazarust See line 13 in cenpy/explorer.py:

cenpy/cenpy/explorer.py

Lines 12 to 35 in f767140

resp = raw_APIs = r.get("https://api.census.gov/data.json")
try:
resp.raise_for_status()
raw_APIs = resp.json()["dataset"]
APIs = {
entry["identifier"]
.split("id")[-1]
.lstrip("/"): {
key: value for key, value in diter(entry) if key != entry["identifier"]
}
for entry in raw_APIs
}
except r.HTTPError:
raise r.HTTPError(
"The main Census API Endpoint (https://api.census.gov/data.json) is not available."
" Try visiting https://api.census.gov/data.json in a web browser to verify connectivity."
)
except JSONDecodeError:
raise JSONDecodeError(
"The main Census API Endpoint (https://api.census.gov/data.json) returned malformed content."
" Try visiting https://api.census.gov/data.json in a web browser to verify connectivity."
)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants