Skip to content

Need special case for SVG files in network.check_reponse()? #57

Closed
adafruit/Adafruit_CircuitPython_PyPortal
#120
@caternuson

Description

@caternuson

This guide:
https://learn.adafruit.com/pyportal-discord-online-count/overview
uses code:
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PyPortal_Discord/code.py
that parses the XML found in a downloaded SVG using regex. That requires a return type of CONTENT_TEXT from check_response() for the PyPortal library to work as expected:
https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/8031c95bbb209a2e4ad5bec7628fd02a4614da40/adafruit_pyportal/__init__.py#L310

However, this library will end up returning CONTENT_IMAGE since the fetch headers will contain content-type: image/svg_html.

def _detect_content_type(self, headers):
if "content-type" in headers:
if "image/" in headers["content-type"]:
return CONTENT_IMAGE
for json_type in self._json_types:
if json_type in headers["content-type"]:
return CONTENT_JSON
return CONTENT_TEXT

That breaks the code for the above guide.

Opening issue here, but could maybe be fixed in one of the higher level libraries, like PyPortal?

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