python 3.5 update causing TypeError with writing to csv with s3io -
i think there's issue using s3io (v0.1.1) , python3.5
typeerror: bytes-like object required, not 'str'
is raised when try following:
with s3io.open(csv_s3_bucket_path, mode='w', **s3_creds) occupancy: writer = csv.writer(occupancy, delimiter=',', quotechar='"', quoting=csv.quote_none) raw_titles = ["p_id", "isodayofweek", "localtimeofdaystart", "localtimeofdayend", "predictedoccupancy"] writer.writerow(raw_titles)
things i've tried:
- adding
b
in front of each string. - turning array bytearray utf-8 encoding
- changing mode 'wt', 'wb', or 'w'
this tells me problem in 1 of 2 places:
writerow
believe changing byte object create changes str- something s3io not work python 3.5's csv writer
any appreciated!
as requested:
--> 595 writer.writerow(raw_titles) 596 lot_id, lot_occs in list(corrected_occ.items()): 597 if not lot_cache.get(lot_id): /usr/lib/python3.5/tempfile.py in func_wrapper(*args, **kwargs) 620 @_functools.wraps(func) 621 def func_wrapper(*args, **kwargs): --> 622 return func(*args, **kwargs) 623 # avoid closing file long wrapper alive, 624 # see issue #18879. typeerror: bytes-like object required, not 'str'
update:
this either fix or work around s3io module, works - build file without csv module.
with s3io.open(csv_s3_bucket_path, mode='w', **s3_creds) occupancy: # first line - p_id,isodayofweek,localtimeofdaystart,localtimeofdayend,predictedoccupancy raw_titles = ["p_id", "isodayofweek", "localtimeofdaystart", "localtimeofdayend", "predictedoccupancy"] occupancy.file.write(",".join(raw_titles).encode("utf-8"))
it seems csv.writer.writerow converts whatever given str, , s3io demands bytes-like object. csv made works other.
Comments
Post a Comment