aiosteampy icon indicating copy to clipboard operation
aiosteampy copied to clipboard

'list object has no attribute items'

Open yesworId opened this issue 6 months ago • 6 comments

Initial Checks

  • [X] I have searched the existing issues for a duplicate and I'm sure this is something new
  • [x] I am confident that the issue in the project code

Description

If you have none listed items, Rendered listings response will return:

{'success': True, 'pagesize': 100, 'total_count': 0, 'assets': [], 'start': 0, 'num_active_listings': 0, 'listings': [], 'listings_on_hold': [], 'listings_to_confirm': [], 'buy_orders': [...]'

Where we can see that assets list is empty.

Later on in _parse_item_descriptions_for_listings method we use assets list (which is empty) and trying to call method 'items':

    def _parse_item_descriptions_for_listings(
        cls: Type["SteamCommunityMixin"],
        assets: dict[str, dict[str, dict[str, dict]]],
        item_descrs_map: dict[str, dict],
    ):
        for app_id, app_data in assets.items():
            for context_id, context_data in app_data.items():
                for a_data in context_data.values():
                    key = create_ident_code(a_data["classid"], app_id)
                    if key not in item_descrs_map:
                        item_descrs_map[key] = cls._create_item_description_kwargs(a_data, [a_data])

I just roughly looked around code and made this small fix by adding if operator (highlighted in the code). I didn't analyze how code works in deep.

    def _parse_item_descriptions_for_listings(
        cls: Type["SteamCommunityMixin"],
        assets: dict[str, dict[str, dict[str, dict]]],
        item_descrs_map: dict[str, dict],
    ):
        if assets:  # < -- BUY ADDING THIS LINE
            for app_id, app_data in assets.items():
                for context_id, context_data in app_data.items():
                    for a_data in context_data.values():
                        key = create_ident_code(a_data["classid"], app_id)
                        if key not in item_descrs_map:
                            item_descrs_map[key] = cls._create_item_description_kwargs(a_data, [a_data])

Steps To Reproduce

  1. Ensure you have no items listed
  2. Call get_my_listings method
  3. Get error "list object has no attribute items."

Environment

- Windows
- Python
- aiosteampy==0.5.4

Additional Information

No response

yesworId avatar Aug 08 '24 19:08 yesworId