This commit is contained in:
2024-07-06 04:14:50 +03:00
parent 283bc95bf4
commit e90d2e72d2
2 changed files with 7 additions and 4 deletions

View File

@@ -16,11 +16,13 @@ class WildberriesMarketplaceApi(BaseMarketplaceApi):
self.marketplace = marketplace
auth_data = json.loads(marketplace.auth_data)
token = auth_data.get('token')
self.is_valid = True
try:
decoded_token = jwt.decode(token, algorithms=["HS256"], options={"verify_signature": False})
except Exception:
logging.error(f"Couldn't decode token for {marketplace.id}")
return None
self.is_valid = False
return
self.limiter_key = str(marketplace.company_id) + str(decoded_token.get('sid'))
self.headers = {
@@ -38,6 +40,9 @@ class WildberriesMarketplaceApi(BaseMarketplaceApi):
async def update_stocks(self, data: Union[list, dict]):
if type(data) is not list:
return
if not self.is_valid:
logging.warning(f'Skipping marketplace [{self.marketplace.id}] because of invalid token')
return
max_stocks = 1000
chunks = utils.chunk_list(data, max_stocks)
limiter = BatchLimiter()