You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Problem

When trying to write out a GRIB or BUFR message to a file using codes_write, an error is generated.

Solution

You have written the following snippet to save a message into a file:

fout = open('temp.out', 'w')
codes_write(msg, fout)
fout.close()

The call to codes_write throws an exception:

Traceback (most recent call last):
  File "encode.py", line 85, in <module>
    sys.exit(main())
  File "encode.py", line 74, in main
    example(sys.argv[1])
  File "encode.py", line 61, in example
    codes_write(bufr, fout)
  ...
    fileobj.write(msg_bytes)
TypeError: write() argument must be str, not bytes


Make sure you are using the BINARY MODE for reading and writing
  1. Replace the 'w' with 'wb' in the call to open



  • No labels