Skip to content

Commit 03705d0

Browse files
fix #269; get_product_info() fail for packages requiring access_token
Valve introduced access_tokens to packages that can be found in liceneses
1 parent 8725143 commit 03705d0

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

steam/client/builtins/apps.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class Apps(object):
10-
licenses = None #: :class:`dict` Account licenses
10+
licenses = None #: :class:`dict` Accounts' package licenses
1111

1212
def __init__(self, *args, **kwargs):
1313
super(Apps, self).__init__(*args, **kwargs)
@@ -57,9 +57,12 @@ def get_product_info(self, apps=[], packages=[], timeout=15):
5757
'packages': {123: {...}, ...}
5858
}
5959
60-
When a token is needed to access the full info (e.g. branches and depots) the ``_missing_token``
61-
will be set to ``True``. The token can be obtained by calling :meth:`get_access_tokens` if
62-
the account has a license.
60+
Access token is needed to access full information for certain apps, and also package info.
61+
Each app and package has its' own access token.
62+
If a token is required then ``_missing_token=True`` in the response.
63+
64+
App access tokens are obtained by calling :meth:`get_access_tokens`, and are returned only
65+
when the account has a license for the specified app. Example code:
6366
6467
.. code:: python
6568
@@ -68,9 +71,21 @@ def get_product_info(self, apps=[], packages=[], timeout=15):
6871
if result['apps'][123]['_missing_token']:
6972
tokens = client.get_access_token(apps=[123])
7073
71-
result = client.get_product_info(apps={'appid': 123,
72-
'access_token': tokens['apps'][123]
73-
})
74+
result = client.get_product_info(apps=[{'appid': 123,
75+
'access_token': tokens['apps'][123]
76+
}])
77+
78+
.. note::
79+
It is best to just request access token for all apps, before sending a product info
80+
request.
81+
82+
Package tokens are located in the account license list. See :attr:`.licenses`
83+
84+
.. code:: python
85+
86+
result = client.get_product_info(packages=[{'packageid': 123,
87+
'access_token': client.licenses[123].access_token,
88+
}])
7489
"""
7590
if not apps and not packages:
7691
return
@@ -107,7 +122,7 @@ def get_product_info(self, apps=[], packages=[], timeout=15):
107122
data['apps'][app.appid] = vdf.loads(app.buffer[:-1].decode('utf-8', 'replace'))['appinfo']
108123
data['apps'][app.appid]['_missing_token'] = app.missing_token
109124
for pkg in chunk.packages:
110-
data['packages'][pkg.packageid] = vdf.binary_loads(pkg.buffer[4:])[str(pkg.packageid)]
125+
data['packages'][pkg.packageid] = vdf.binary_loads(pkg.buffer[4:]).get(str(pkg.packageid), {})
111126
data['packages'][pkg.packageid]['_missing_token'] = pkg.missing_token
112127

113128
if not chunk.response_pending:

steam/client/cdn.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ def load_licenses(self):
478478
self._LOG.debug("No steam licenses found on SteamClient instance")
479479
return
480480

481-
packages = list(self.steam.licenses.keys())
481+
packages = list(map(lambda l: {'packageid': l.package_id, 'access_token': l.access_token},
482+
itervalues(self.steam.licenses)))
482483

483484
for package_id, info in iteritems(self.steam.get_product_info(packages=packages)['packages']):
484485
self.licensed_app_ids.update(info['appids'].values())

0 commit comments

Comments
 (0)