How can I configure CCSID value in my Queue Manager using "pymqi" Python library?

In your code you create a default message descriptor for the message you send in this line of code:

request_md = pymqi.MD()

By default pymqi (like the underlying IBM MQ C libraries) will set the message descriptor CodedCharSetId to the value CMQC.MQCCSI_Q_MGR.

This can be seen in the source:

['CodedCharSetId', CMQC.MQCCSI_Q_MGR, MQLONG_TYPE],

The IBM MQ v9.0 KC page Reference > Developing applications reference > MQI applications reference > Data types used in the MQI > MQMD - Message descriptor > Fields for MQMD > CodedCharSetId (MQLONG) describes how the client handles this:

For client applications, MQCCSI_Q_MGR is filled in, based on the locale of the client rather than the one on the queue manager.


The IBM MQ Troubleshooting document What CCSID is used by default for WebSphere MQ client messages explains this in a slightly different way:

A MQ client sets the MQCCSI_Q_MGR value based on the environment in which the client application is running.


Based on the 850 CCSID I would guess you are running on a Windows OS that is not in the United States (which commonly uses CCSID 437).


You have a few options to override this:

  1. You can programmatically override the pymqi MQMD default value like this:

    request_md.CodedCharSetId = 1208
    
  2. Set the env variable MQCCSID to the value you want (in your case 1208). This must be set before you connect to mq. This is documented in the IBM MQ v9.0 KC page Developing applications > Developing MQI applications with IBM MQ > Writing client procedural applications > Using the MQI in a client application > Choosing client or server CCSID.

    The example below is for Windows:

    SET MQCCSID=1208
    
  3. In the mqclient.ini you can set the CCSID=number under the CHANNELS stanza. This is documented in the IBM MQ v9.0 KC page Configuring > Configuring connections between the server and client > Configuring a client using a configuration file > CHANNELS stanza of the client configuration file. For example:

    CHANNELS:
       CCSID=1208
    

You shouldn't need to change the CCSID of the queue manager. Your problem is that your message contains UTF-8 characters, but you have sent it in an envelope describing it as containing CCSID 850 characters. You simply need to update the envelope delivering your message to correctly describe your content.

I am an IBM MQ expert and a 'C' programmer, but not a pymqi programmer, however, looking at the pymqi help and your example, I would expect these are the required additions to your code.

# set message descriptor
request_md = pymqi.MD()
request_md.ReplyToQ = self.queue_response_name
request_md.Format = pymqi.CMQC.MQFMT_STRING
request_md.CodedCharSetId = 1208

The pymqi help does not include any examples of use of the CodedCharSetId, but it would seem that all pymqi fields in the MQMD follow the exact same spelling and case as those in the 'C' API header file cmqc.h.

Please try this and see if it solves your problem.