Skip to content

Response

The response module offers a structured representation of responses from OAI-PMH services.

This module defines the OAIResponse class, which encapsulates the HTTP response from an OAI-PMH server, providing easy access to its content both as raw text and as parsed XML. It is designed to work seamlessly with various components of an OAI-PMH client, handling the nuances of OAI-PMH responses.

OAIResponse dataclass

Represents a response received from an OAI server, encapsulating the raw HTTP response and parsed XML content.

This class provides a structured way to access various aspects of an OAI server's response. It offers methods to retrieve the raw text of the response, parse it as XML, and obtain a string representation of the response that includes the OAI verb.

Attributes:

Name Type Description
http_response Response

The original HTTP response object from the OAI server.

params dict[str, str]

A dictionary of the OAI parameters used in the request that led to this response.

raw property

Return the raw text of the server's response as a unicode string.

xml property

Parse the server's response content and return it as an etree.Element object.

raise_for_oaipmh_error()

Check for OAI-PMH error elements in the XML response and raise the corresponding exception.

Parses the response XML to detect elements. If found, extracts the error code and message, then raises the appropriate exception from oaipmh_scythe.exceptions based on the error code. Non-XML responses are silently ignored.

Raises:

Type Description
BadArgument

When the OAI response contains an error with code="badArgument".

BadResumptionToken

When the OAI response contains an error with code="badResumptionToken".

BadVerb

When the OAI response contains an error with code="badVerb".

CannotDisseminateFormat

When the OAI response contains an error with code="cannotDisseminateFormat".

IdDoesNotExist

When the OAI response contains an error with code="idDoesNotExist".

NoMetadataFormats

When the OAI response contains an error with code="noMetadataFormats".

NoRecordsMatch

When the OAI response contains an error with code="noRecordsMatch".

NoSetHierarchy

When the OAI response contains an error with code="noSetHierarchy".

GeneralOAIPMHError

When the error code is unknown, empty, or the exception class cannot be resolved.