Jun-17-2018, 09:37 AM
Hi,
I am new to Python and Jupyter Notebook and I get the error below in Jupyter Notebook while the code works in Spyder:
I am new to Python and Jupyter Notebook and I get the error below in Jupyter Notebook while the code works in Spyder:
import base64 import json import subprocess def output_image(name, format, bytes): image_start = "BEGIN_IMAGE_f9825uweof8jw9fj4r8" image_end = "END_IMAGE_0238jfw08fjsiufhw8frs" data = {} data['name'] = name data['format'] = format data['bytes'] = base64.encodestring(bytes) print(image_start + json.dumps(data) + image_end)
Error:TypeError Traceback (most recent call last)
<ipython-input-16-f9e8ef7a162f> in <module>()
1 ### draw the decision boundary with the text points overlaid
2 instanceCV.prettyPicture(clf, features_test, labels_test)
----> 3 instanceCV.output_image("test.png", "png", open("test.png", "rb").read())
<ipython-input-10-99476019b17b> in output_image(self, name, format, bytes)
71 data['format'] = format
72 data['bytes'] = base64.encodestring(bytes)
---> 73 print(image_start + json.dumps(data) + image_end)
C:\ProgramData\Anaconda3\lib\json\__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder
C:\ProgramData\Anaconda3\lib\json\encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
C:\ProgramData\Anaconda3\lib\json\encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
Thanks for help