Install & Compatibility
Where this runs
tested against v8.0 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.305s · 33.1MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.7s · import 0.281s · 34MB
36MB installed
● package 36MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
HTTPRequest
✓ from zope.publisher.http import HTTPRequest
✗ from zope.publisher import HTTPRequest
HTTPRequest and HTTPResponse are located in the `http` submodule.
HTTPResponse
✓ from zope.publisher.http import HTTPResponse
✗ from zope.publisher import HTTPResponse
HTTPRequest and HTTPResponse are located in the `http` submodule.
IPublisher
✓ from zope.publisher.interfaces import IPublisher
Zope components are heavily interface-driven, often found in the `interfaces` submodule.
This quickstart demonstrates how to create and interact with `HTTPRequest` and `HTTPResponse` objects, which are the fundamental data structures `zope.publisher` operates on. It shows how to simulate a WSGI environment, access request properties like URL, method, and headers, and set response status, headers, and body. This is crucial for understanding how data flows through the Zope publishing process.
from io import BytesIO
from zope.publisher.http import HTTPRequest, HTTPResponse
# Simulate a WSGI-like environment for the request
request_environ = {
'REQUEST_METHOD': 'GET',
'PATH_INFO': '/my/path',
'QUERY_STRING': 'param1=value1¶m2=value2',
'SERVER_NAME': 'localhost',
'SERVER_PORT': '8080',
'wsgi.input': BytesIO(b''), # For GET, body is usually empty
'wsgi.url_scheme': 'http',
'HTTP_HOST': 'localhost:8080',
'CONTENT_TYPE': 'text/plain; charset=utf-8',
}
# Create a request object
# The first argument (input_stream) can be a BytesIO or similar for POST bodies
request = HTTPRequest(BytesIO(b''), request_environ)
# Create a response object
response = HTTPResponse()
# --- Interact with the Request ---
print(f"Request URL: {request.getURL()}")
print(f"Request Method: {request.method}")
print(f"Path Info: {request.getURL('PATH_INFO')}")
print(f"Query parameters (combined form): {request.form}")
print(f"Request header 'Host': {request.get('HTTP_HOST')}")
# --- Interact with the Response ---
response.setStatus(200)
response.setHeader('Content-Type', 'text/html; charset=utf-8')
response.setBody('<h1>Hello from Zope Publisher!</h1>')
print(f"\nResponse Status: {response.getStatus()}")
print(f"Response Header 'Content-Type': {response.getHeader('Content-Type')}")
print(f"Response Body: {response.consumeBody().decode('utf-8')}")
Errors
Common errors & fixes
TypeError: Can't adapt <your_object> to zope.publisher.interfaces.IRequest
The object you are passing as a request to a Zope publisher function (or related component) does not implement the `IRequest` interface, or no suitable adapter is registered for it.
fixEnsure your request object is an instance of `zope.publisher.http.HTTPRequest` or `zope.publisher.browser.BrowserRequest` (for browser contexts), or explicitly implements `zope.publisher.interfaces.IRequest` and its sub-interfaces via `zope.interface.implementer`.
ImportError: cannot import name 'HTTPRequest' from 'zope.publisher'
You are trying to import `HTTPRequest` (or `HTTPResponse`) directly from the top-level `zope.publisher` package.
fixThe `HTTPRequest` and `HTTPResponse` classes are located in the `zope.publisher.http` submodule. Correct your import statement to `from zope.publisher.http import HTTPRequest`.
AttributeError: 'HTTPRequest' object has no attribute 'form' or 'POST' data is missing.
When handling POST requests, `request.form` combines query string parameters and POST body data. If `wsgi.input` (the stream for the request body) was not correctly provided or the `CONTENT_TYPE` was incorrect, POST data might not be parsed.
fixFor POST requests, ensure the `request_environ['wsgi.input']` is a file-like object containing the raw request body bytes, and `request_environ['CONTENT_TYPE']` is set appropriately (e.g., `application/x-www-form-urlencoded` or `multipart/form-data`) so `HTTPRequest` can parse it.
Upgrade
Version history
8.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredCore Zope component, widely used for defining interfaces and adapting objects.
zope.traversingrequiredUsed for hierarchical object traversal, a fundamental aspect of Zope's URL dispatch.
zope.securityrequiredProvides security concepts for Zope, often integrated with publishing decisions.