Skip to content
New issue

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

JSON serializer can't serialize binary data: UnicodeDecodeError: 'utf8' error #51

Closed
dotIN opened this issue Dec 2, 2013 · 7 comments
Closed
Labels

Comments

@dotIN
Copy link

dotIN commented Dec 2, 2013

When I try to upload or download a .zip file, i see the above error, If i make a plain requests call it works , but with vcr I see the above error
Guess this is happening while serialising the content , with this error the cassette never gets created

Here is the stack -

File "/Library/Python/2.7/site-packages/vcr/cassette.py", line 127, in exit
self._save()
File "/Library/Python/2.7/site-packages/vcr/cassette.py", line 88, in _save
serializer=self._serializer
File "/Library/Python/2.7/site-packages/vcr/persist.py", line 10, in save_cassette
data = serializer.serialize(cassette_dict)
File "/Library/Python/2.7/site-packages/vcr/serializers/jsonserializer.py", line 34, in serialize
return json.dumps(data, indent=4, default=_json_default)
File "/Library/Python/2.7/site-packages/simplejson/init.py", line 369, in dumps
**kw).encode(obj)
File "/Library/Python/2.7/site-packages/simplejson/encoder.py", line 264, in encode
chunks = list(chunks)
File "/Library/Python/2.7/site-packages/simplejson/encoder.py", line 600, in _iterencode
for chunk in _iterencode_list(o, _current_indent_level):
File "/Library/Python/2.7/site-packages/simplejson/encoder.py", line 455, in _iterencode_list
for chunk in chunks:
File "/Library/Python/2.7/site-packages/simplejson/encoder.py", line 568, in _iterencode_dict
for chunk in chunks:
File "/Library/Python/2.7/site-packages/simplejson/encoder.py", line 568, in _iterencode_dict
for chunk in chunks:
File "/Library/Python/2.7/site-packages/simplejson/encoder.py", line 535, in _iterencode_dict
yield _encoder(value)

@kevin1024
Copy link
Owner

yeah looks like it's having trouble serializing the binary data.

@dotIN
Copy link
Author

dotIN commented Dec 5, 2013

Any plan on a fix for this issue

@kevin1024
Copy link
Owner

Sorry, I've been really busy and haven't had a chance to check it out. Do you have the same problem with the yaml serializer?

On Dec 5, 2013, at 6:03 AM, Raghavendra Kumar notifications@github.com wrote:

Any plan on a fix for this issue


Reply to this email directly or view it on GitHub.

@kevin1024
Copy link
Owner

It looks like the problem is that JSON can't serialize binary data. The response contains the binary zip file, which can't be encoded into UTF-8.

I'm not sure what the solution here is. I could base64 encode the response string, but that would break backwards compatibility with old JSON cassettes as well as defeat the ability to open the cassette file to inspect the response for debugging purposes.

@dotIN
Copy link
Author

dotIN commented Dec 9, 2013

Sorry forgot to mention, it does work with yaml

@MashaAseeva
Copy link

Any updates on this issue - I'm having the same issue and would prefer to use json over yaml for the serializer due to performance issues loading in the yaml file.

@kevin1024
Copy link
Owner

Maybe a new serializer: base64-encoded json???

For the yaml performance issue - make sure you are using the libyaml c bindings instead of falling back to the pure python implementation - it’s a lot faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants