Skip to content

Conversation

@suojae
Copy link

@suojae suojae commented Oct 25, 2025

Summary

When headers contain non-ASCII characters, the error message now includes the header name to make debugging easier.


Before:

httpx.Headers({"Authorization": "Bearer valid", "X-Custom": "안녕"})
# UnicodeEncodeError: 'ascii' codec can't encode characters...
# Which header failed? 

After:

  httpx.Headers({"Authorization": "Bearer valid", "X-Custom": "안녕"})
  # UnicodeEncodeError: Header 'X-Custom' value contains non-ASCII characters
  # Clear which header is the problem 

Changes

  • Added optional header_name parameter to _normalize_header_key and _normalize_header_value
  • Updated error messages to include header name when encoding fails
  • Added tests for both header key and value encoding errors

related #3400

When headers contain non-ASCII characters, the error message now
includes the header name to make debugging easier.

Fixes encode#3400
@suojae suojae changed the title fix: Include header name in encoding error messages chore: Include header name in encoding error messages Oct 25, 2025
When headers contain non-ASCII characters, the error message now
includes the header name to make debugging easier.

Fixes encode#3400
@suojae suojae changed the title chore: Include header name in encoding error messages Include header name in encoding error messages Oct 25, 2025
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.

1 participant