[issue32358] json.dump: fp must be a text file object

2018-03-23 Thread Berker Peksag

Berker Peksag  added the comment:

This is already documented in the json.dump() documentation:

The json module always produces str objects, not bytes objects.
Therefore, fp.write() must support str input.

Note that the traceback you've posted doesn't have anything to do with the json 
module and it's expected:

>>> f = open('/tmp/t.json', 'wb')
>>> f.write('foo')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: a bytes-like object is required, not 'str'

--
nosy: +berker.peksag
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32358] json.dump: fp must be a text file object

2017-12-17 Thread TaoQingyun

New submission from TaoQingyun <845767...@qq.com>:

```
>>> import json
>>> f = open('/tmp/t.json', 'wb')  
>>> json.dump(123, f)  
Traceback (most recent call last): 
  File "", line 1, in   
  File "/usr/lib/python3.6/json/__init__.py", line 180, in dump 
  
fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'
```

This may not a bug. But it should mention at docs 
https://docs.python.org/3/library/json.html#json.dump

--
components: Library (Lib)
messages: 308517
nosy: qingyunha
priority: normal
severity: normal
status: open
title: json.dump: fp must be a text file object
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com