We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi,
Whenever I use a byte format field with pyswagger and Python 3 and pass in a Python bytes object, I hit an exception like the one below.
byte
pyswagger
bytes
Looking at the code to convert the bytes to JSON here, this actually returns bytes and not a str, matching the docs here:
str
>>> import base64 >>> base64.urlsafe_b64encode(b'abcdef') b'YWJjZGVm'
And passing that to the JSONEncoder causes a TypeError as below.
JSONEncoder
TypeError
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
I think Byte.to_json() should return a str - I'll try and create a pull request with a fix.
Byte.to_json()
Thanks!
The text was updated successfully, but these errors were encountered:
Bytes
to_json
[VERSION]
7ccc337
[fix] Unable to use byte type parameters with Python 3 #120 (by Oliver Pratt)
@olipratt Hi, thanks for your PR, and your fix is included in v0.8.29, which is just released.
Sorry, something went wrong.
Thanks for the heads-up!
d6d38b2
[fix] Unable to use byte type parameters with Python 3 pyopenapi/pyswagger#120 (by Oliver Pratt)
No branches or pull requests
Hi,
Whenever I use a
byte
format field withpyswagger
and Python 3 and pass in a Pythonbytes
object, I hit an exception like the one below.Looking at the code to convert the bytes to JSON here, this actually returns
bytes
and not astr
, matching the docs here:And passing that to the
JSONEncoder
causes aTypeError
as below.I think
Byte.to_json()
should return astr
- I'll try and create a pull request with a fix.Thanks!
The text was updated successfully, but these errors were encountered: