Skip to content

Cannot read messages with RFH2 headers written by IBM Java classes #19

@henschkowski

Description

@henschkowski

Hello,

We try to read RFH2 messages from a topic with the sub.get_rfh2() method. We get an exception:

Traceback (most recent call last):
  File "/home/ralf/dev/testcasetool/.venv/lib/python3.12/site-packages/ibmmq/mqrfh2.py", line 176, in unpack
    folder_name = ET.fromstring(folder_data).tag
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/xml/etree/ElementTree.py", line 1335, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: unbound prefix: line 1, column 74

The message was written by a Java application using the IBM MQ classes. The message/ RFH2 headers can be read with "MQ Explorer".

The folder_data for the usr folder looks like this:

<usr><CREATED>2026-03-12T11:11:47.000000000+01:00</CREATED><VERS>25</VERS><ABC xsi:nil='true'></ABC></usr>

So there is an attribute "xsi:nil", and the xsi namespace is not declared.

When replacing the ET.fromstring() with something like the following, the message can be read:

        g = re.match(b"^<(\\S+?)", folder_data)
                if g:
                    folder_name = str(g[1])

Could you please fix this?
Although this is a fault of the writing application, I think it might be user friendly to make it compatible with the Java libraries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions