>>> import base64
>>> base64.urlsafe_b64encode(b'abcdef')
b'YWJjZGVm'
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\pyswagger\contrib\client\requests.py", line 40, in request
req.prepare(scheme=self.prepare_schemes(req), handle_files=False)
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\pyswagger\io.py", line 217, in prepare
content_type, self.__data = self._prepare_body()
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\pyswagger\io.py", line 83, in _prepare_body
return content_type, self.__op._mime_codec.marshal(content_type, body, _type=_type, _format=_format, name=name)
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\pyswagger\primitives\codec.py", line 29, in marshal
return codec.marshal(value, **kwargs)
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\pyswagger\primitives\codec.py", line 48, in marshal
return json.dumps(value, cls=PrimJSONEncoder)
File "C:\Program Files (x86)\Python 3.5\lib\json\__init__.py", line 237, in dumps
**kw).encode(obj)
File "C:\Program Files (x86)\Python 3.5\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Program Files (x86)\Python 3.5\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\pyswagger\primitives\comm.py", line 12, in default
return json.JSONEncoder.default(self, obj)
File "C:\Program Files (x86)\Python 3.5\lib\json\encoder.py", line 180, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'AA==' is not JSON serializable
Hi,
Whenever I use a
byteformat field withpyswaggerand Python 3 and pass in a Pythonbytesobject, I hit an exception like the one below.Looking at the code to convert the bytes to JSON here, this actually returns
bytesand not astr, matching the docs here:And passing that to the
JSONEncodercauses aTypeErroras below.I think
Byte.to_json()should return astr- I'll try and create a pull request with a fix.Thanks!