...
When trying to write out a GRIB or BUFR message to a file using codes_write, an error is generated .(an exception is thrown)
Solution
You have written the following snippet to save a message into a binary file (GRIB or BUFR):
Code Block |
---|
|
fout = open('temp.out', 'w')
codes_write(msg, fout)
fout.close() |
...
Code Block |
---|
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(bufrmsg, fout)
...
fileobj.write(msg_bytes)
TypeError: write() argument must be str, not bytes |
...
Panel |
---|
|
Make sure you are using the BINARY MODE for reading and writing
- Replace the 'w' with 'wb' in the call to open
fout = open('temp.out', 'wb') - This mode should be used for all files that do not contain text.
|
Related articles
Content by Label |
---|
showLabels | false |
---|
max | 5 |
---|
spaces | UDOC |
---|
showSpace | false |
---|
sort | modified |
---|
reverse | true |
---|
type | page |
---|
cql | label = "python3" and label = "python3" and type = "page" and space = "UDOC" |
---|
labels | python3 |
---|
|
...