question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CsvItemExporter fails on py3

See original GitHub issue
from scrapy.exporters import CsvItemExporter
with open('temp.csv', 'w') as f:
    exporter = CsvItemExporter(f)
    exporter.start_exporting()
    exporter.export_item({'a': 'b'})
    exporter.finish_exporting()

The previous snippet works fine on python 2, however the following error appears when running on python 3:

Traceback (most recent call last):
  File "exporter.py", line 5, in <module>
    exporter.export_item({'a': 'b'})
  File "/Users/eugenio/.../venv/lib/python3.5/site-packages/scrapy/exporters.py", line 206, in export_item
    self._write_headers_and_set_fields_to_export(item)
  File "/Users/eugenio/.../venv/lib/python3.5/site-packages/scrapy/exporters.py", line 230, in _write_headers_and_set_fields_to_export
    self.csv_writer.writerow(row)
TypeError: write() argument must be str, not bytes

Am I missing something? Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kmikecommented, Feb 14, 2017

That’d be awesome!

0reactions
elacuestacommented, Feb 14, 2017

Thanks, makes sense now 😄 I’ll make a PR to mention this in the docs, if that’s OK.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I have a trouble when use scrapy to write item to csv file
I try to write to csv file in Scrapy using CsvItemExporter. ... representation of `text` (bytes in Python 2.x and unicode in Python...
Read more >
[Example code]-Error while merging multiple csv with a condition
Requirement: I have 69 csvs. Merge them on the basis of below condition: Condition: If value in cell at header 'col7' = 1,...
Read more >
latest PDF - Scrapy Documentation
Scrapy (/skrepa/) is an application framework for crawling web sites and extracting structured data which can be used.
Read more >
Release notes — Scrapy 2.5.0 documentation - Read the Docs
The __init__ method of CsvItemExporter now supports an errors parameter to ... Extended use of InterSphinx to link to Python 3 documentation (issue...
Read more >
transistor - PyPI
In this case, we are just going to use the built-in CsvItemExporter but we could ... handling failures with automatic retries, and setting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found