stefanitsky/yandex_market_language

Error parsing seller_warranty tag

Closed this issue · 2 comments

  • Yandex Market Language (YML) for Python version: 0.6.0
  • Python version: 3.8.3
  • Operating System: Windows 10 v. 1909 (build num 18363.836)

Description

When I try to parse a file that has a tag called <seller_warranty> I get an error. I attach the log below.

What I Did

Code

import argparse
from typing import Optional

import yandex_market_language as yml


class YMLParser:

    def __init__(self, file: str, count: Optional[int] = None):
        self.feed = yml.parse(file)
        self.data = self.feed.to_dict()


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('file', help='.yml or .xml file to parse')
    parser.add_argument('-c', '--count', type=int, help='minimum count of items to add them to separate file')

    args = parser.parse_args()

    if not args.file:
        raise ValueError('You need to select file for parse')

    yml_parser = YMLParser(args.file, args.count)
    print(yml_parser.data)

File template

<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog date="2020-04-14 12:00">
	<shop>
		<name>...</name>
		<company>...</company>
		<url>...</url>		
		<categories>There is some <category> tags </categories>
                <offers>
                             <offer>
                             // Some tags with information about offer

                             // Empty tag <seller_warranty>
                             <seller_warranty></seller_warranty>
                             </offer>
                 </offers>
        </shop>
</yml_catalog>

Log error

Traceback (most recent call last):
  File "C:/Users/god/PycharmProjects/yml_parser/app/main.py", line 24, in <module>
    yml_parser = YMLParser(args.file, args.count)
  File "C:/Users/god/PycharmProjects/yml_parser/app/main.py", line 10, in __init__
    self.feed = yml.parse(file)
  File "C:\Users\god\.virtualenvs\virtualenvs\yml-parser-GzhhnpNv-py3.8\lib\site-packages\yandex_market_language\yml.py", line 44, in parse
    return YML(file_or_path).parse()
  File "C:\Users\god\.virtualenvs\virtualenvs\yml-parser-GzhhnpNv-py3.8\lib\site-packages\yandex_market_language\yml.py", line 30, in parse
    return Feed.from_xml(root)
  File "C:\Users\god\.virtualenvs\virtualenvs\yml-parser-GzhhnpNv-py3.8\lib\site-packages\yandex_market_language\models\feed.py", line 44, in from_xml
    shop = Shop.from_xml(el[0])
  File "C:\Users\god\.virtualenvs\virtualenvs\yml-parser-GzhhnpNv-py3.8\lib\site-packages\yandex_market_language\models\shop.py", line 183, in from_xml
    offer = models.ArbitraryOffer.from_xml(offer_el)
  File "C:\Users\god\.virtualenvs\virtualenvs\yml-parser-GzhhnpNv-py3.8\lib\site-packages\yandex_market_language\models\offers.py", line 536, in from_xml
    return ArbitraryOffer(**kwargs)
  File "C:\Users\god\.virtualenvs\virtualenvs\yml-parser-GzhhnpNv-py3.8\lib\site-packages\yandex_market_language\models\offers.py", line 506, in __init__
    super().__init__(vendor=vendor, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'seller_warranty'

@divaltor hi! Thank you for the feedback, but i can't find such a tag in the docs.

You can remove it from the file or manually expand the AbstractOffer class from yandex_market_language/models/offers.py. I understand that this is uncomfortable, but for more customization and flexibility, i will need to rewrite the entire logic of the package, which is hardly planned in the near future.

@divaltor hi! Thank you for the feedback, but i can't find such a tag in the docs.

You can remove it from the file or manually expand the AbstractOffer class from yandex_market_language/models/offers.py. I understand that this is uncomfortable, but for more customization and flexibility, i will need to rewrite the entire logic of the package, which is hardly planned in the near future.

Thanks for the answer! It will be easier to remove unnecessary tags in the file than to rewrite the package, your truth)