Hi Kevin,

Thanks for taking the time to reply.

I don't know if you had a particular command line program in mind for
setting the CCSID but it seems to me that the easiest way to achieve it
might be to use the CHGATR command.
It's certainly simpler from a 'user' perspective than coding up a call to

Seeking about for information on how to call AS400 Commands / Programs from
Python lead me to a post which I noticed you had contributed to:


And so that lead me to try a test of:

from itoolkit import *
from itoolkit.lib.ilibcall import *
itransport = iLibCall()
itool = iToolKit()
itool.add(iCmd('sndmsg', 'SNDMSG "WIBBLE" RICHARC'))
output = itool.dict_out('sndmsg')

This works from Python 3.4.6 and prints:
{'success': '+++ success SNDMSG "WIBBLE" RICHARC'}

However if I run it from Python 3.6.6 ( /QopenSys/pkgs/bin/python3 ) it
fails and prints:
{'error': {'error': '*NODATA', 'sndmsg': {...}}}

If my memory serves me correctly, 3.4.6 is what came with the system and I
installed 3.6.6 via IBMi ACS Open Source Package Management.

I'm not sure what the problem is with this, forgive my ignorance.

Another thing which also puzzled me is that the documentation for itoolkit
which you kindly linked in your post:


is different to the code you supplied in the original post and doesn't work
for me with either version of python.
For example the code for DSPSYSSTS:
import config
from itoolkit import *
itool = iToolKit()
itool.add(iCmd5250('dspsyssts', dspsyssts'))

This codes fails from both versions of python with:
AttributeError: 'module' object has no attribute 'itransport'

So that leaves me with the following questions:

1. Is CHGATR from python a reasonable way to set the "tag" of the IFS
file. I guess there might be something I can run more directly from QSH via
subprocess() that might let me set the CCSID.
2. Is itoolkit a reasonable way to make the call to CHGATR. I'm a little
confused about it being called an XMLSERVICE collector but is that just the
way it is communicating with the OS?
3. Why doesn't my example work with Python 3.6.6 - is it running a
different version of itoolkit? using help() for iCmd, the syntax looked
4. Are the code examples for itoolkit wrong or is it to do with change
code versions or assumed imports or something?

Sorry for my ignorance and the many questions.
What can I say, I'm a curious man...

thanks and best regards,

On Mon, 1 Oct 2018 at 17:29, Kevin Adler <kadler@xxxxxxxxxx> wrote:

Python has its own built-in codecs and does not use the system codecs.
can see the list (which does not include cp285) here:

As Python runs in PASE it will open the file tagged with whatever the
ccsid is (which defaults to 819 except in rare cases). There is
no mechanism in Python to match the CCSID tag with the encoding of the
data, though there are various command line programs you could call
manually from within Python to do so.

----- Original message -----
From: Craig Richards <craig@xxxxxxxxxxxxxxxx>
Sent by: "OpenSource" <opensource-bounces@xxxxxxxxxxxx>
To: IBMi Open Source Roundtable <opensource@xxxxxxxxxxxx>
Subject: [IBMiOSS] Creating Stream Files with Python
Date: Mon, Oct 1, 2018 11:13 AM

Hi All,

I can create streamfiles with different encodings in the IFS using
using the encoding parameter and this works fine e.g:

f = open('asci.txt', 'w', encoding='cp819')

This is good. And fine too. Some might say dandy.
However if I look at the attributes of the stream file it is always
819 if I am creating a new file.

This means that using DSPF to look at the data on the IBMi will
data incorrectly if that data is not actually written with encoding

I can modify the file manually using EDTF to change the file's CCSID
then it will be displayed correctly ( within the limitations of the
Client ) however I assume there is a way to set this attribute
for new files using python?
I understand that the IBMi is fairly unique in that it has additional
attributes on stream files that store information such as the
ccsid but I know it is possible to set these correctly when using the
open API to create stream files ( for example )

Additionally I'm using an IBMi in the UK and QCCSID is set to 285, I
error in the above code if I specify encoding='cp285' although it is
happy to use encoding='cp037'.

Not that I have a requirement to encoding in the IFS in 285 but I was
little surprised that 37 was supported but not 285 - especially given
it is a UK not US box.

However my main question is - should I be using a different method to
create my streamfiles if I want the endcoding of the streamfile ( the
header, not the actual data ) to be other than 819?

I've tried using the codecs.open method but that seems to work the
it creates the data correctly but the CCSID for the file itself is
819 for NEW files.

Thanks kindly,
This is the IBMi Open Source Roundtable (OpenSource) mailing list
To post a message email: OpenSource@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: [2]https://lists.midrange.com/mailman/listinfo/opensource
or email: OpenSource-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at [3]https://archive.midrange.com/opensource.


Visible links
1. https://docs.python.org/3/library/codecs.html#standard-encodings
2. https://lists.midrange.com/mailman/listinfo/opensource
3. https://archive.midrange.com/opensource
This is the IBMi Open Source Roundtable (OpenSource) mailing list
To post a message email: OpenSource@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/opensource
or email: OpenSource-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/opensource.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.