Python 3 and iToolkit error
Hello, I tried to execute the following program from the IBM supplied examples in /QOpenSys/QIBM/ProdData/OPS/Python3.4/lib/python3.4/site-packages/itoolkit/sample:
python3 icmd5250_dspsyssts.py
and got the following error:
Traceback (most recent call last):
File "icmd5250_dspsyssts.py", line 16, in <module>
itool.call(config.itransport)
File "/QOpenSys/QIBM/ProdData/OPS/Python3.4/lib/python3.4/site-packages/itoolkit/itoolkit.py", line 1098, in call
xml_out = itrans.call(self)
File "/QOpenSys/QIBM/ProdData/OPS/Python3.4/lib/python3.4/site-packages/itoolkit/lib/ilibcall.py", line 88, in call
return itoolkit.itoollib.xmlservice(itool.xml_in(),self.ctl,self.ipc,self.ebcdic_ccsid,self.pase_ccsid)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 802: ordinal not in range(128)
Attached you can find information about the environment variables the the Python modules installed.
Thank you Siegfried
Comments (7)
-
Account Deleted -
reporter Hello Tony, thank you for the answer. The only solution that works is using idb2call(). Any other try throws the same error mentioned above. But with idb2Call() there must be passed a user id and a password. Passing a generic user id like QPGMR I get the wrong job attributes for user X. Is there any possibility to use the current user id for iTransport?
Thank you Siegfried
-
Account Deleted UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3
Mm, python-itoolkit iLibCall may be able make a change to help. That is, experimenting with python 2 (works) vs. python 3 (not work), we think changing c-code for iLibCall may help.
bash-4.3$ python italy.py ... ok <?xml version="1.0" ?><xmlservice><fake>non \u00E8 domani</fake></xmlservice> bash-4.3$ python3 italy.py ... bad Traceback (most recent call last): File "italy.py", line 16, in <module> File "/QOpenSys/QIBM/ProdData/OPS/Python3.4/lib/python3.4/site-packages/itoolkit/itoolkit.py", line 1098, in call xml_out = itrans.call(self) File "/QOpenSys/QIBM/ProdData/OPS/Python3.4/lib/python3.4/site-packages/itoolkit/lib/ilibcall.py", line 88, in call return itoolkit.itoollib.xmlservice(itool.xml_in(),self.ctl,self.ipc,self.ebcdic_ccsid,self.pase_ccsid) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 44: ordinal not in range(128) bash-4.3$ cat italy.py # -*- coding: utf-8 -*- : itool.add(iXml('<fake>non \u00E8 domani</fake>')) # utf-8 :
So, I will attempt modify c code (itoollib.so), and build a new wheel (egg). I can post the 'test wheel fix' on Yips (soon).
Will you be willing to test in your environment?
iDb2Call (ibm_db python)
I did not check null user/password.
-
Account Deleted python3-itoolkit - change iLibCall - fix UnicodeDecodeError
Ok, I have a new wheel on Yips for download.
Works latin-1 or utf-8 test
latin-1
bash-4.3$ python3 italy-latin-1.py <?xml version="1.0" ?><xmlservice><fake>non � domani</fake></xmlservice>
# -*- coding: latin-1 -*- from itoolkit import iToolKit from itoolkit import iXml from itoolkit.lib.ilibcall import iLibCall itransport = iLibCall("*here *cdata") # *debug i will stop, inquiry message qsysopr itool = iToolKit() #itool.add(iXml("it's not tomorrow")) itool.add(iXml('<fake>non è domani</fake>')) # latin-1 itool.call(itransport) print(itool.xml_out())
utf-8
bash-4.3$ python3 italy-utf-8.py <?xml version="1.0" ?><xmlservice><fake>non � domani</fake></xmlservice>
# -*- coding: utf-8 -*- from itoolkit import iToolKit from itoolkit import iXml from itoolkit.lib.ilibcall import iLibCall itransport = iLibCall("*here *cdata") # *debug i will stop, inquiry message qsysopr itool = iToolKit() # itool.add(iXml('<fake>non è domani</fake>')) # latin-1 itool.add(iXml('<fake>non \u00E8 domani</fake>')) # utf-8 itool.call(itransport) print(itool.xml_out())
-
Account Deleted python3-itoolkit - change iLibCall - fix UnicodeDecodeError
YIPs python3-itoolkit-1.3.zip - change iLibCall - fix UnicodeDecodeError: ascii codec cannot decode byte 0xc3
Please download fix 1.3 and install with pip3 (above). Let us know if it works for you.
-
reporter Hello Tony, yes I installed the new itoolkit 1.3 and it works. Thousand thanks for you effort. Mille grazie
Siegfried
-
Account Deleted - changed status to resolved
Great. Thanks for testing.
- Log in to comment
You may have to try these things one at a time. We are faced with a daunting ebcdic task as IBM i has not allowed a unicode job description (cough, just sayin' ... whining he did)
Note: Depending on shell following env settings have different built-ins for 'export'. Assuming modern shell like bash 'export' works. I cannot recall qp2term (evil death of all joy green screen abomination qp2term ... not that i have opinion).
0) env.txt - You have confusing LANG settings, possibly inherited shell settings. We see both generic ascii LANG=C (active) and Italian PASE_LANG=it_IT (not active).
0) env.txt - switch to UTF-8 pase ccsid (CCSID=1208). Your env has QIBM_PASE_CCSID=819 and CCSID=819. Python 3 loves UTF-8 (1208) ... and ... nothing else ... nothing else ... nothing else. Cough, you could try python 2 with more liberal view of NLS (did i say that out loud?).
Try new things ...
1) Switch to iDB2Call transport. DB2 implicit convert ascii/ebcdic (no human fumbling). This may be you best option.
Try old things a new way ...
2) Try override ccsid in iLibCall (your current memory transport)