ipython/ipython — Issue #1037: notepad + jsonlib: TypeError: Only whitespace may be used for indentation.
Author: wolever
Created: 2011-11-24 18:15:08+00:00
State: open

When `jsonlib` is installed, the notepad crashes with a `TypeError`:

```
Traceback (most recent call last):
...
File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.6/site-packages/IPython/zmq/kernelmanager.py", line 752, in start_kernel
self.write_connection_file()
File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.6/site-packages/IPython/zmq/kernelmanager.py", line 716, in write_connection_file
shell_port=self.shell_port, hb_port=self.hb_port)
File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.6/site-packages/IPython/zmq/entry_point.py", line 86, in write_connection_file
f.write(json.dumps(cfg, indent=2))
File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.6/site-packages/zmq/utils/jsonapi.py", line 67, in jsonlib_dumps
return _squash_unicode(jsonmod.dumps(o,**kwargs))
File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.6/site-packages/jsonlib.py", line 799, in write
return write_impl (value, sort_keys, validate_indent (indent), ascii_only,
File "/Users/wolever/code/sandbox/env/sandbox/lib/python2.6/site-packages/jsonlib.py", line 812, in validate_indent
raise TypeError ("Only whitespace may be used for indentation.")
TypeError: Only whitespace may be used for indentation.
```

It looks like this is because `jsonlib` expects the `indent` argument to be string, while the stdlib's `json` expects `indent` to be a number. The offending code is below:

```
> /Users/wolever/code/sandbox/env/sandbox/lib/python2.6/site-packages/IPython/zmq/entry_point.py(86)write_connection_file()
-> f.write(json.dumps(cfg, indent=2))
(Pdb) list
81	)
82	cfg['ip'] = ip
83	cfg['key'] = bytes_to_str(key)
84
85	with open(fname, 'wb') as f:
86 ->	f.write(json.dumps(cfg, indent=2))
87
88	return fname, cfg
89
90
91	def base_launch_kernel(code, fname, stdin=None, stdout=None, stderr=None,
```

The above is Python 2.6.7 on OS X 10.7 with jsonlib 1.6.1.

Uninstalling `jsonlib` (presumably forcing a fallback to stdlib `json`?) fixes this issue.