Why when replacing meta in method:

def parse_product(self, response): product = response.meta['product'] ......... new_meta= {} ......... response = response.replace(meta=new_meta) 

I get an error:

 exceptions.TypeError: __init__() got an unexpected keyword argument 'meta' 

Python 2.7, Scrapy 0.24.4

  • Because you don't have the meta keyword in your list - Igor Lavrynenko
  • I am sure that there is a meta in response. It is used immediately at the beginning of the method (added a line to the question) - sky
  • and if you try this way - response.meta = new_meta and you can add the output print(dir(response)) - Igor Lavrynenko
  • no, it doesn't work exceptions.AttributeError: can't set attribute - sky
  • And if so: setattr(response, '_{class_name}__meta'.format(class_name=type(response).__name__), new_meta) - Andrio Skur

1 answer 1

parse_product is a class method which is a descendant of scrapy.Spider? If so, then maybe you redefined the init () method and did not call scrapy.Spider. init