Install & Compatibility
Where this runs
tested against v0.8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
multipart_encode
✓ from poster3.encode import multipart_encode
✗ from poster.encode import multipart_encode
StreamingHTTPHandler
✓ from poster3.streaminghttp import StreamingHTTPHandler
✗ from poster.streaminghttp import StreamingHTTPHandler
encode
✓ from poster3 import encode
✗ from poster import encode
This quickstart demonstrates how to use `poster3` to upload a file along with other form data using `urllib.request`. It registers the streaming HTTP handlers, encodes the multipart data, and then sends the request. Remember to replace `POSTER3_TEST_URL` with your actual endpoint.
import os
import urllib.request
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
# Register the streaming http handlers with urllib2
register_openers()
# Prepare file and simple field for upload
filename = 'test_upload.txt'
with open(filename, 'w') as f:
f.write('This is a test file for poster3 upload.')
# 'datagen' is a generator object that yields ranges of the encoded multipart data
# 'headers' is a dictionary of headers that must be included with the request
datagen, headers = multipart_encode({"field1": "value1", "file1": open(filename, "rb")})
# In a real scenario, you'd replace this with your actual upload URL
upload_url = os.environ.get('POSTER3_TEST_URL', 'http://httpbin.org/post')
# Create the request object
request = urllib.request.Request(upload_url, datagen, headers)
# Actually upload the file
print(f"Uploading to {upload_url}...")
try:
response = urllib.request.urlopen(request)
print("Upload successful!")
print(response.read().decode('utf-8'))
except urllib.error.URLError as e:
print(f"Upload failed: {e.reason}")
finally:
# Clean up the test file
os.remove(filename)
Debug
Known issues
breakingThe GitHub repository mentions a 'Version 0.9 Notice' indicating a complete internal rewrite and a shift from scattered functions to object-managed APIs. While 0.8.1 is the latest PyPI release, be aware that future versions (>=0.9) will likely introduce significant breaking changes to the API structure.fixReview the `poster3` documentation or README for version 0.9 and above to understand the new object-oriented API if upgrading beyond 0.8.1. Stick to 0.8.1 for the current function-based API.
affects: >=0.9.0 (unreleased at time of 0.8.1)
gotchaThe library's last release was in December 2018. This means it may not be actively maintained and might have compatibility issues with very recent Python versions (e.g., Python 3.9+) or modern HTTP client libraries. Consider testing thoroughly in your target environment.fixTest `poster3` in your specific Python environment. For new projects, evaluate more actively maintained alternatives like `requests-toolbelt` for multipart encoding, or built-in `http.client` if direct streaming control is needed.
affects: All versions, especially with Python >3.8
gotchaWhen opening files for upload, always use binary read mode ('rb'). Using text mode ('r') can lead to `TypeError` or incorrect encoding, especially on Windows where text mode might perform newline translations.fixEnsure `open(filename, 'rb')` is used for all file parameters passed to `multipart_encode`.
affects: All versions
Upgrade
Version history
0.8.1latest on PyPI · released Dec 15, 2018
Audit
Dependencies
No dependency data recorded yet.