Skip to content

need to handle TIGERweb errors better #167

Description

@dotysan

As of right now today, https://tigerweb.geo.census.gov/ is throwing errors when request are made via IPv6. This module crashes instead of properly handling the error.

q = q.json()

The bug is it assumes json. When in fact, their server is returning 200 with html instead.

<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 13427891533456682816</body></html>

Here's one way to handle/display the error. After q.raise_for_status() and before attemping q.json():

    ct = q.headers.get("Content-Type", "")
    if ct.startswith("text/html"):
        raise RuntimeError(q.text)
    if not ct.startswith("application/json"):
        msg = "Unexpected content type for TIGERweb service info"
        raise RuntimeError(msg)

You'll need to force IPv6 to reproduce. I've sent a bug report to the TIGERweb admins. So this test case might go away once they fix IPv6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions