pyx12 icon indicating copy to clipboard operation
pyx12 copied to clipboard

ERROR Failed to create 999 response- X12 file validation

Open jasirmuhammad opened this issue 5 years ago • 4 comments

I have got an issue while validating an X12 EDI file through command line. TypeError: a bytes-like object is required, not 'str'. Also help me to do this validation through python console.

The command I'm using is: x12valid <path> --verbose

jasirmuhammad avatar Jan 30 '20 08:01 jasirmuhammad

Which line in which source file is throwing the error? Can you post the full traceback?

victor-roy avatar Mar 04 '20 22:03 victor-roy

@victor-roy
ERROR Failed to create 999 response Traceback (most recent call last): File "c:\python\python37-32\lib\site-packages\pyx12\x12n_document.py", line 252, in x12n_document errh.accept(visit_999) File "c:\python\python37-32\lib\site-packages\pyx12\error_handler.py", line 101, in accept visitor.visit_root_pre(self) File "c:\python\python37-32\lib\site-packages\pyx12\error_999.py", line 83, in visit_root_pre self.wr.Write(isa_seg) File "c:\python\python37-32\lib\site-packages\pyx12\x12file.py", line 495, in Write self._write_isa_segment(seg_data) File "c:\python\python37-32\lib\site-packages\pyx12\x12file.py", line 582, in _write_isa_segment self.fd_out.write(out) File "C:\Python\Python37-32\Lib\tempfile.py", line 481, in func_wrapper return func(*args, **kwargs) TypeError: a bytes-like object is required, not 'str'

jasirmuhammad avatar May 06 '20 10:05 jasirmuhammad

@azoner, @victor-roy

Using Python3 v3.8.5 on Windows... when running x12valid.py (v2.3.3) specifically, down stack in x12file.py, any line with: self.fd_out.write(out) results in "TypeError: a bytes-like object is required, not 'str'".

Hack to force self.fd_out.write(bytes(out, encoding='ascii')) opens up a can of worms in downstream processing as there is bytes to string conversion needed if the hack is applied - so that is not the simple fix.

I am still debugging - but I assume that wherever x12valid.py code calls x12file.X12Writer - the "src_file_obj" needs to have the correct mode as tempfile._TemporaryFileWrapper. If anyone who knows the code base better can suggest the quick fix, I can try it and apply and do a pull request. Otherwise, given extra time (aka boredeom) and/or an urgent need to get x12valid working - hopefully can figure it out.

ddw360 avatar Apr 24 '21 16:04 ddw360

@azoner, @victor-roy , @jasirmuhammad

In x12valid.py, making this change: - fd_997 = tempfile.TemporaryFile() + fd_997 = tempfile.TemporaryFile(mode='r+') seems to work.

ddw360 avatar Apr 24 '21 17:04 ddw360