added the str() type cast to the row to fix the following error:#44
added the str() type cast to the row to fix the following error:#44HadManySons wants to merge 1 commit intocsu:masterfrom
Conversation
Traceback (most recent call last):
File ".\export_saved.py", line 244, in write_csv
csvwriter.writerow(csv_fields)
TypeError: a bytes-like object is required, not 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\export_saved.py", line 253, in write_csv
csvwriter.writerow(row)
File "H:\Programs\Python\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f61c' in position 168: character maps to <undefined>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\export_saved.py", line 329, in <module>
main()
File ".\export_saved.py", line 323, in main
save_saved(reddit)
File ".\export_saved.py", line 287, in save_saved
process(reddit, seq, "export-saved", "Reddit - Saved")
File ".\export_saved.py", line 269, in process
write_csv(csv_rows, file_name + ".csv")
File ".\export_saved.py", line 255, in write_csv
csvwriter.writerow(row.encode('utf-8', 'ignore'))
AttributeError: 'list' object has no attribute 'encode'
Codecov Report
@@ Coverage Diff @@
## master #44 +/- ##
======================================
Coverage 94.9% 94.9%
======================================
Files 1 1
Lines 157 157
======================================
Hits 149 149
Misses 8 8
Continue to review full report at Codecov.
|
| csvwriter.writerow(row) | ||
| except UnicodeEncodeError: | ||
| csvwriter.writerow(row.encode('utf-8', 'ignore')) | ||
| csvwriter.writerow(str(row).encode('utf-8', 'ignore')) |
There was a problem hiding this comment.
row here is a list, so str type cast it will create error on the csv writer.
|
When I ran the script, I got this error because it was trying to pass a list, in the exception. Adding the str() type cast fixed the issue, for me anyway. Without it, I got the error above after about 200 saved links. |
|
can you post the error traceback? |
|
Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): |
Traceback (most recent call last):
File ".\export_saved.py", line 244, in write_csv
csvwriter.writerow(csv_fields)
TypeError: a bytes-like object is required, not 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\export_saved.py", line 253, in write_csv
csvwriter.writerow(row)
File "H:\Programs\Python\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f61c' in position 168: character maps to
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\export_saved.py", line 329, in
main()
File ".\export_saved.py", line 323, in main
save_saved(reddit)
File ".\export_saved.py", line 287, in save_saved
process(reddit, seq, "export-saved", "Reddit - Saved")
File ".\export_saved.py", line 269, in process
write_csv(csv_rows, file_name + ".csv")
File ".\export_saved.py", line 255, in write_csv
csvwriter.writerow(row.encode('utf-8', 'ignore'))
AttributeError: 'list' object has no attribute 'encode'