Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Special Characters Issue When Consuming API with Flutter/Dart #11

Open
xsampedro opened this issue Feb 20, 2024 · 2 comments
Open

Special Characters Issue When Consuming API with Flutter/Dart #11

xsampedro opened this issue Feb 20, 2024 · 2 comments

Comments

@xsampedro
Copy link

xsampedro commented Feb 20, 2024

Issue Description

I've encountered an encoding issue when consuming the web service using the Flutter/Dart HTTP client. The client seems to default to latin1 encoding when the Content-Type header lacks a specified charset, resulting in misinterpreted special characters.

Impact

This issue impacts any client that relies on the Content-Type header to determine the correct character encoding. Since the Flutter/Dart HTTP client defaults to latin1, it incorrectly decodes responses that include special characters, assuming the absence of a charset=utf-8 in the Content-Type header.

Steps to Reproduce

  1. Consume the API endpoint using Flutter/Dart HTTP client.
  2. Notice special characters are not displayed correctly.

Proposed Solution

To resolve this issue, I suggest explicitly setting the charset in the Content-Type header for JSON responses. This can be implemented in the _process_api_query function.

from fastapi.responses import JSONResponse

# Modify the _process_api_query function to return a JSONResponse with charset=utf-8
if not use_csv:
    return JSONResponse(content=results, media_type="application/json; charset=utf-8")
else:
    # Existing CSV handling logic

By specifying charset=utf-8 in the Content-Type header, clients like Flutter/Dart should correctly interpret the response encoding as UTF-8.

@PrestonHager
Copy link
Contributor

@xsampedro has your issue been fixed with the release of v1.0? I have not seen issues on my projects yet.

@vitoramaral10
Copy link

Hello!

I'm having the same problem with the GP São Paulo meeting, for my Flutter App showing São Paulo.

I fixed it using utf8.decode(json['meeting_name'].runes.toList()),

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 a pull request may close this issue.

3 participants