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

🐛 Bug Report: FormatException: Invalid HTTP header field value #74

Open
2 tasks done
Evgentret opened this issue Feb 18, 2025 · 9 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@Evgentret
Copy link

👟 Reproduction steps

After updating to Dart 3.7 had error with database.listDocuments, running as console app

👍 Expected behavior

Get a valid response as I did yesterday (Same code on previous version of Dart works fine)

👎 Actual Behavior

"FormatException: Invalid HTTP header field value: "AppwriteDartSDK/13.0.0 (windows; "Майкрософт Windows 10 Домашняя для одного языка" 10.0 (Build 19045))" (at character 35)"
AppwriteDartSDK/13.0.0 (windows; "Майкрософт Windows 10 Домашняя для одного...
^

🎲 Appwrite version

Different version (specify in environment)

💻 Operating system

Windows

🧱 Your Environment

Appwrite version 1.6.0 on self-hosted Linux VPS, dart_appwrite: 13.0.0

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@Evgentret Evgentret added the bug Something isn't working label Feb 18, 2025
@ChiragAgg5k
Copy link
Member

@Evgentret From the error, it seems like you are passing invalid characters in your User-Agent header in the request, "Майкрософт Windows 10 Домашняя для одного языка" the header contains Cyrillic characters which aren't allowed in HTTP headers.

Can you please the snippet of the code that is leading to this error?

Also can you confirm if switching the language to English makes it work?

@Evgentret
Copy link
Author

Evgentret commented Feb 20, 2025

@Evgentret From the error, it seems like you are passing invalid characters in your User-Agent header in the request, "Майкрософт Windows 10 Домашняя для одного языка" the header contains Cyrillic characters which aren't allowed in HTTP headers.

Can you please the snippet of the code that is leading to this error?

Also can you confirm if switching the language to English makes it work?

This is code snippet that raise error:

import 'package:dart_appwrite/dart_appwrite.dart' as app;

...
  app.Client client = app.Client();
  late app.Databases database;
...
    client
        .setEndpoint(uEndpoint)
        .setProject(uProject)
        . setKey(uToken );
    database = app.Databases(client);

...

 try {
      var docs = await database.listDocuments(databaseId: uDBID,
          collectionId: uUser, queries: [app.Query.equal('tgId', id)]);
      if (docs.total>0) {
        user = UserModel.fromDoc(docs.documents.first);
      } else {
        await database.createDocument(databaseId: uDBID,
            collectionId: uUser, documentId: uid, data: user.toJson());
      }
    } on Exception catch (e) {
      print ('error on getting user $e');
    }

That's all. This code work well on previous dart version. I didn't set any headers (I think that SDK don't allowed it), I can't switch language. I just run the code as I ran it before Dart upgrade

@ChiragAgg5k
Copy link
Member

@Evgentret thanks for sharing this! since the issue arised after updating of dart and not the sdk, can you confirm if downgrading the dart version fixes it?

@Evgentret
Copy link
Author

@Evgentret thanks for sharing this! since the issue arised after updating of dart and not the sdk, can you confirm if downgrading the dart version fixes it?

Yes. Right now I clone flutter 3.27.3, herer is:

PS C:\flutter> flutter doctor -v
[!] Flutter (Channel [user-branch], 3.27.3, on Microsoft Windows [Version 10.0.19045.5487], locale ru-RU)
! Flutter version 3.27.3 on channel [user-branch] at C:\flutter
Currently on an unknown channel. Run flutter channel to switch to an official channel.
If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
! Upstream repository unknown source is not a standard remote.
Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
• Framework revision c519ee916e (4 weeks ago), 2025-01-21 10:32:23 -0800
• Engine revision e672b006cb
• Dart version 3.6.1
• DevTools version 2.40.2

All working best. Sorry, I don't know how to show you this, because just no errors and code works as it should

@Evgentret
Copy link
Author

@Evgentret thanks for sharing this! since the issue arised after updating of dart and not the sdk, can you confirm if downgrading the dart version fixes it?

And come back again:

PS C:\flutter> flutter doctor -v
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version 10.0.19045.5487], locale ru-RU) [918ms]
• Flutter version 3.29.0 on channel stable at C:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 35c388afb5 (10 days ago), 2025-02-10 12:48:41 -0800
• Engine revision f73bfc4522
• Dart version 3.7.0
• DevTools version 2.42.2

:

AppwriteException: , FormatException: Invalid HTTP header field value: "AppwriteDartSDK/13.0.0 (windows; "Майкрософт Windows 10 Домашняя для одного языка" 10.0 (Build 19045))" (at character 35)
AppwriteDartSDK/13.0.0 (windows; "Майкрософт Windows 10 Домашняя для одного...

So, issue only with new dart version

@ChiragAgg5k
Copy link
Member

@Evgentret Thanks for sharing this! I have raised the issue to the internal team to look into it further

@ChiragAgg5k
Copy link
Member

@Evgentret in the meanwhile while we look into it, a fix i can suggest for now would be to manually set the user-agent field using Client#addHeader

@stnguyen90
Copy link
Contributor

What's Platform.operatingSystem on both the version on flutter?

@Evgentret
Copy link
Author

What's Platform.operatingSystem on both the version on flutter?

windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants