Skip to content

fix: resolve UTF-8 encoding issues in HTTP request bodies#158

Merged
luk384090-cloud merged 5 commits into
mainfrom
dev/issue2
Jul 2, 2026
Merged

fix: resolve UTF-8 encoding issues in HTTP request bodies#158
luk384090-cloud merged 5 commits into
mainfrom
dev/issue2

Conversation

@lzsweb

@lzsweb lzsweb commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator
  • Add charset=utf-8 to Content-Type and Accept headers
  • Serialize JSON with ensure_ascii=False for proper UTF-8 encoding
  • Fix body size calculation to prevent Content-Length mismatches
  • Apply changes to sync HTTP, async HTTP, WebSocket, and form data paths
  • Add comprehensive unit and integration tests

This fix reduces request body size by 57.5% for non-ASCII content (e.g., 12.41MB → 5.27MB for websearch.json test data) and ensures compatibility with servers that enforce strict body size limits.

Closes issue with large UTF-8 payloads exceeding server limits.

Description

[Describe what this PR does and why]

Related Issue: Fixes #[issue_number] or Relates to #[issue_number]

Security Considerations: [Check if API keys or sensitive credentials are exposed in code/logs]

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Model
  • Application
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Testing

[How to test these changes]

Additional Notes

[Optional: any other context]

- Add charset=utf-8 to Content-Type and Accept headers
- Serialize JSON with ensure_ascii=False for proper UTF-8 encoding
- Fix body size calculation to prevent Content-Length mismatches
- Apply changes to sync HTTP, async HTTP, WebSocket, and form data paths
- Add comprehensive unit and integration tests

This fix reduces request body size by 57.5% for non-ASCII content
(e.g., 12.41MB → 5.27MB for websearch.json test data) and ensures
compatibility with servers that enforce strict body size limits.

Closes issue with large UTF-8 payloads exceeding server limits.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the SDK to support UTF-8 encoding for JSON payloads across HTTP, async HTTP, and WebSocket requests by using ensure_ascii=False and explicitly setting charset=utf-8 in headers. It also adds comprehensive integration and unit tests to verify these changes. The reviewer feedback highlights a critical backward compatibility issue where renaming the json parameter to json_body in the update and put methods of base_api.py will break existing callers using keyword arguments. The reviewer suggests keeping the parameter optional and resolving the legacy json key from kwargs to maintain compatibility.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread dashscope/client/base_api.py
Comment thread dashscope/client/base_api.py Outdated
Comment thread dashscope/client/base_api.py
Comment thread dashscope/client/base_api.py Outdated
kevin and others added 4 commits July 1, 2026 18:23
The 'json' parameter in UpdateMixin.update() and PutMixin.put() shadowed
the 'json' module, causing AttributeError when calling json.dumps().
Use local 'import json as _json' alias to avoid the conflict while
keeping the public API parameter name unchanged.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
These local config directories should not be tracked in git.
They are now properly excluded via .gitignore.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@luk384090-cloud luk384090-cloud merged commit 5ff5c86 into main Jul 2, 2026
3 checks passed
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 this pull request may close these issues.

2 participants