Skip to content
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

AttributeError when exporting non-string types through XMLFeedExporter #1738

Closed
stummjr opened this issue Jan 27, 2016 · 1 comment
Closed

AttributeError when exporting non-string types through XMLFeedExporter #1738

stummjr opened this issue Jan 27, 2016 · 1 comment
Labels
bug
Milestone

Comments

@stummjr
Copy link
Member

@stummjr stummjr commented Jan 27, 2016

Scrapy 1.0.4 fails to export items to XML when those items have non-string types. I tested it with a spider that generates an item like this: {'int': 2, 'boolean1': True, 'boolean2': False, 'time': datetime.datetime(2015, 1, 1, 1, 1, 1)}.

Here is what I got when running the Spider to export XML items:

$ scrapy runspider example.py -o items.xml
...
2016-01-27 15:55:42 [scrapy] DEBUG: Scraped from <200 http://www.example.com/>
{'int': 2, 'boolean': True, 'boolean2': False, 'time': datetime.datetime(2015, 1, 1, 1, 1, 1)}
2016-01-27 15:55:42 [scrapy] ERROR: Error caught on signal handler: <bound method ?.item_scraped of <scrapy.extensions.feedexport.FeedExporter object at 0x7f5f70075650>>
Traceback (most recent call last):
  File "/home/stummjr/.virtualenvs/scrapy/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 150, in maybeDeferred
    result = f(*args, **kw)
  File "/home/stummjr/.virtualenvs/scrapy/local/lib/python2.7/site-packages/scrapy/xlib/pydispatch/robustapply.py", line 57, in robustApply
    return receiver(*arguments, **named)
  File "/home/stummjr/.virtualenvs/scrapy/local/lib/python2.7/site-packages/scrapy/extensions/feedexport.py", line 193, in item_scraped
    slot.exporter.export_item(item)
  File "/home/stummjr/.virtualenvs/scrapy/local/lib/python2.7/site-packages/scrapy/exporters.py", line 130, in export_item
    self._export_xml_field(name, value)
  File "/home/stummjr/.virtualenvs/scrapy/local/lib/python2.7/site-packages/scrapy/exporters.py", line 146, in _export_xml_field
    self._xg_characters(serialized_value)
  File "/home/stummjr/.virtualenvs/scrapy/local/lib/python2.7/site-packages/scrapy/exporters.py", line 157, in _xg_characters
    serialized_value = serialized_value.decode(self.encoding)
AttributeError: 'int' object has no attribute 'decode'
...
@redapple
Copy link
Contributor

@redapple redapple commented Feb 3, 2016

Will not be backported to 1.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.