-
Notifications
You must be signed in to change notification settings - Fork 35
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
added the str() type cast to the row to fix the following error: #44
base: master
Are you sure you want to change the base?
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.
|
@@ -252,7 +252,7 @@ def write_csv(csv_rows, file_name=None): | |||
try: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'