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

Py3: Encode strings when compressing #187

Closed
TomAugspurger opened this issue Apr 30, 2015 · 2 comments · Fixed by #188
Closed

Py3: Encode strings when compressing #187

TomAugspurger opened this issue Apr 30, 2015 · 2 comments · Fixed by #188
Assignees
Labels
Milestone

Comments

@TomAugspurger
Copy link

Another drive by report. Maybe I'll contribute someday :) This one should be easy

In [1]: import odo

In [2]: with open('tst.csv', 'w') as f:
    f.write('a,1\nb,2\nc,3')
   ...:

In [3]: !cat tst.csv
a,1
b,2
c,3
In [4]: odo.odo('tst.csv', 'tst.csv.gz')

raises

...
/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/gzip.py in write(self, data)
    341         if len(data) > 0:
    342             self.size = self.size + len(data)
--> 343             self.crc = zlib.crc32(data, self.crc) & 0xffffffff
    344             self.fileobj.write( self.compress.compress(data) )
    345             self.offset += len(data)

TypeError: 'str' does not support the buffer interface

I believe that

ipdb> zlib.crc32(data.encode('utf-8'), self.crc) & 0xffffffff
2324740828

Or something like sys.defaultencoding instead of utf-8 is the fix.

In [5]: odo.__version__
Out[5]: '0.3.2'
@cpcloud cpcloud added this to the Someday milestone Apr 30, 2015
@cpcloud
Copy link
Member

cpcloud commented Apr 30, 2015

Hm actually, this looks like a bug.

@cpcloud
Copy link
Member

cpcloud commented Apr 30, 2015

Thanks for the report!

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

Successfully merging a pull request may close this issue.

2 participants