Closed
Description
I'd been having difficulty connecting the view server with CouchDB, as the view server died before it sent a response. The logs produced the following lines again and again:
[2017-05-24 15:14:03,749] [ERROR] Error: write() argument must be str, not bytes
Traceback (most recent call last):
File "c:\...\couchdb\view.py", line 164, in run
_writejson(retval)
File "c:\...\couchdb\view.py", line 55, in _writejson
output.write(obj)
TypeError: write() argument must be str, not bytes
It appears that the write function no longer accepts bytes objects. I'm not sure when this change was made, but it's more recent than 2.7 and at least as recent as 3.5.
I verified that this was the only problem by wrapping the output stream with a class to redefine write. It works fine after this change. (Probably not the prettiest solution, but it works!)
class betterout():
def __init__(self, out):
self.out = out
def __getattr__(self, attr):
if attr == 'write':
return self.write
else:
return getattr(self.out, attr)
def write(self, text, *args, **kwargs):
if isinstance(text, str):
self.out.write(text, *args, **kwargs)
else:
self.out.write(text.decode('utf-8'), *args, **kwargs)
Has anyone else run into this problem? Is there a more standard solution to the problem?
Metadata
Metadata
Assignees
Labels
No labels