From 537493deaa0b8e18a3fa72eb1b3eeae9ef043b11 Mon Sep 17 00:00:00 2001 From: Gregory Arenius Date: Tue, 14 Jan 2020 14:19:22 -0800 Subject: [PATCH] Fix string instead of bytes-like object error. Running x12norm with python3 I received the following error: Traceback (most recent call last): File "/usr/local/bin/x12norm", line 11, in sys.exit(main()) File "/usr/local/lib/python3.6/dist-packages/pyx12/scripts/x12norm.py", line 71, in main fd_out.write(seg_data.format() + eol) TypeError: a bytes-like object is required, not 'str' fd_out is a "tempfile.TemporaryFile()". The tempfile docs state: The mode parameter defaults to 'w+b' so that the file created can be read and written without being closed. Binary mode is used so that it behaves consistently on all platforms without regard for the data that is stored. In other parts of the x12norm code mode 'w' is set explicitly so I think it is okay to do so for the tempfile as well. This commit does that. --- pyx12/scripts/x12norm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyx12/scripts/x12norm.py b/pyx12/scripts/x12norm.py index 4dfa8fdc..543758ff 100755 --- a/pyx12/scripts/x12norm.py +++ b/pyx12/scripts/x12norm.py @@ -52,7 +52,7 @@ def main(): if not os.path.isfile(file_in): logger.error('Could not open file "%s"' % (file_in)) - fd_out = tempfile.TemporaryFile() + fd_out = tempfile.TemporaryFile(mode='w') src = pyx12.x12file.X12Reader(file_in) for seg_data in src: if args.fixcounting: