1.1
This release introduces a critical fix for handling binary responses, such as images or PDFs, ensuring they are properly decoded and accessible through response.content
and response.text
.
🔧 Summary of Changes
The Go-based TLS client now always returns byte-level responses (when isByteResponse=true
) in base64 format with MIME type prefixes like:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASw...
This allows the Python wrapper to:
- Safely decode base64 data
- Preserve binary content integrity
- Avoid UTF-8 decoding errors
The Python side was updated to:
- Handle malformed or missing base64 prefixes gracefully
- Decode response bodies safely
📦 What’s Fixed
1. Binary Response Corruption
Previously, binary data was treated as UTF-8 text, leading to corruption or exceptions when trying to read files like images.
Now, thanks to the Go-side change and updated Python logic:
response = await session.get("https://example.com/image.png")
with open("image.png", "wb") as f:
f.write(response.content) # This now works reliably
2. Text Decoding Improvements
Used errors='replace'
instead of 'ignore'
to avoid silent data loss:
response.text = decoded.decode(errors='replace')
💡 Technical Highlights
Component | Change |
---|---|
Python (response.py ) |
Safely decodes base64 responses and handles malformed ones |
Python (sessions.py ) |
Sets "isByteResponse": True by default |
🐛 Related Issues
This release resolves several long-standing issues related to binary responses:
- FlorianREGAZ/Python-Tls-Client#83
- FlorianREGAZ/Python-Tls-Client#119
- FlorianREGAZ/Python-Tls-Client#117
- FlorianREGAZ/Python-Tls-Client#83
🚀 Installation
pip install -U async_tls_client