Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR Failed to create 999 response- X12 file validation #68

Open
jasirmuhammad opened this issue Jan 30, 2020 · 4 comments
Open

ERROR Failed to create 999 response- X12 file validation #68

jasirmuhammad opened this issue Jan 30, 2020 · 4 comments

Comments

@jasirmuhammad
Copy link

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

@victor-roy
Copy link

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

@jasirmuhammad
Copy link
Author

@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'

@ddw360
Copy link

ddw360 commented Apr 24, 2021

@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
Copy link

ddw360 commented Apr 24, 2021

@azoner, @victor-roy , @jasirmuhammad

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants