adelosa / cardutil

Payment cards tools including ISO8583 parser and Mastercard IPM files processing
MIT License
25 stars 4 forks source link

Error while loading ISO8583 record #14

Closed clarnx closed 1 year ago

clarnx commented 1 year ago

I tried to convert the TT112 file to csv but I get the error below. The command I used was mci_ipm_to_csv --debug TT112T0.2023-07-12-06-20-12.001

Using the option --no1014blocking results in the same error

mci_ipm_to_csv (cardutil 0.6.3)
parameters:
 -in_filename:TT112T0.2023-07-12-06-20-12.001
 -debug:True
DEBUG:cardutil.cli:config_dir=None
DEBUG:cardutil.mciipm:record_length=74
DEBUG:cardutil.mciipm:74: b'\xf1\xf6\xf4\xf4\x80\x00\x01\x00\x00\x01\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\xf6\xf9\xf7\xf0\xf4\xf0\xf0\xf1\xf0\xf5\xf0\xf2\xf5\xf0\xf0\xf1\xf2\xf3\xf0\xf7\xf1\xf2\xf0\xf0\xf0\xf0\xf0\xf0\xf3\xf2\xf8\xf1\xf5\xf0\xf2\xf2\xf0\xf1\xf0\xf1\xf2\xf2\xf0\xf0\xf1\xd7\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf1'
DEBUG:cardutil.iso8583:Processing message: len=74 contents:
00000000: F1 F6 F4 F4 80 00 01 00  00 01 00 00 02 00 00 00  ................
00000010: 00 00 00 00 F6 F9 F7 F0  F4 F0 F0 F1 F0 F5 F0 F2  ................
00000020: F5 F0 F0 F1 F2 F3 F0 F7  F1 F2 F0 F0 F0 F0 F0 F0  ................
00000030: F3 F2 F8 F1 F5 F0 F2 F2  F0 F1 F0 F1 F2 F2 F0 F0  ................
00000040: F1 D7 F0 F0 F0 F0 F0 F0  F0 F1                    ..........
DEBUG:cardutil.iso8583:processing bit 24
DEBUG:cardutil.iso8583:field_data=b'\xf6\xf9\xf7'
DEBUG:cardutil.iso8583:processing bit 48
*** ERROR - processing has stopped ***
Error detected in record 2
Error while loading ISO8583 record
00000000: 00 00 00 4A F1 F6 F4 F4  80 00 01 00 00 01 00 00  ...J............
00000010: 02 00 00 00 00 00 00 00  F6 F9 F7 F0 F4 F0 F0 F1  ................
00000020: F0 F5 F0 F2 F5 F0 F0 F1  F2 F3 F0 F7 F1 F2 F0 F0  ................
00000030: F0 F0 F0 F0 F3 F2 F8 F1  F5 F0 F2 F2 F0 F1 F0 F1  ................
00000040: F2 F2 F0 F0 F1 D7 F0 F0  F0 F0 F0 F0 F0 F1        ..............
adelosa commented 1 year ago

The file is from a mainframe so you will need to specify encoding for input. I ran your record through using 'CP500' encoding and the record processed as follows: {'MTI': '1644', 'DE24': '697', 'DE48': '010502500123071200000032815022010122001P', 'PDS0105': '0012307120000003281502201', 'PDS0122': 'P', 'DE71': 1}

For the CLI, the parameter is --in-encoding

clarnx commented 1 year ago

Hi @adelosa thanks for the feedback. Your suggestion worked. Follow up question. So for example if MTI is 1644 and Function Code (DE 24) is 640 it means Currency Update. Is it possible for the package to convert to human readable format as well instead of codes?

Thanks.

adelosa commented 1 year ago

That's a feature request but my view is it is beyond the scope of this package. You could leverage cardutil library to build a tool to meet your specific requirements. I am available for paid engagements if you want me to build it for you. Contact me via email for more details.

alikulaOwen commented 1 year ago

Hi @adelosa, i have been trying to read ipm file and getting the same error above but really dont understand the issue. only two item are printed then the error logs

 try:
        with open(file, 'rb') as infile:
            file_content = mciipm.IpmReader(infile, encoding='cp500')
            for i in file_content:
                print(i)

  except Exception as e:
        print(f"Error: {e}")

Error: Error while loading ISO8583 record. Could you point what i might be doing wrong. Would appreciate your feedback Thank you

adelosa commented 1 year ago

This indicates that there was an an error parsing the ISO8583 record. This exception captures an inner exception that you should print the details to see what is triggering the error.

 try:
     with open(file, 'rb') as infile:
        file_content = mciipm.IpmReader(infile, encoding='cp500')
            for i in file_content:
                print(i)

  except MciIpmDataError as e:
        print(f"Error: {e}")
        print(f"Inner error: {e.ex}")
        print(f"Record data: {e.ex.binary_context_data}")
        print(f"Record number: {e.record_number}")
alikulaOwen commented 1 year ago

Thanks. it worked after setting args blocked=True. Then, ipm source file one of the field DE55 value is byte string when i try to decode it the code below i get a weird string that is not readable.

b = ls[2]['DE55']
utf8_text = codecs.decode(b, 'cp500')

my target is to export the data to csv.

adelosa commented 1 year ago

De55 is binary data (EMV) so that's probably correct.

alikulaOwen commented 1 year ago

Thanks for your help. I will research on it