Krukov / amocrm_api

Python amocrm API wrapper
MIT License
104 stars 55 forks source link

Ловлю jwt.exceptions.InvalidAudienceError: Invalid audience. Как быть? #49

Closed danilax86 closed 3 years ago

danilax86 commented 3 years ago

Здравствуй! Когда пытаюсь достать или создать Lead, получаю такую ошибку. Помоги, пожалуйста :3

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/__main__.py", line 3, in <module>
    main()
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/cli.py", line 990, in main
    cli.main(args=sys.argv[1:])
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/cli.py", line 596, in main
    return super().main(*args, **kwargs)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/cli.py", line 845, in run_command
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/cli.py", line 321, in __init__
    self._load_unlocked()
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/cli.py", line 346, in _load_unlocked
    self._app = rv = self.loader()
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/cli.py", line 402, in load_app
    app = locate_app(self, import_name, name)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/flask/cli.py", line 256, in locate_app
    __import__(module_name)
  File "/mnt/8A2C66EE2C66D4AB/PyCharmProjects/dialogflow/app.py", line 35, in <module>
    add_lead("TEST", "+79999999999", "eaxmple@example.ru", "10.06.2023", "13:37")
  File "/mnt/8A2C66EE2C66D4AB/PyCharmProjects/dialogflow/app.py", line 33, in add_lead
    Lead.save(Lead(name = name, number = number, email = email, date = date, time = time))
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/model.py", line 23, in __init__
    setattr(self, attr, value)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/entity/custom_field.py", line 147, in __set__
    self._check(instance)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/entity/custom_field.py", line 99, in _check
    field = self._find(instance)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/entity/custom_field.py", line 91, in _find
    for field in CustomFieldModel.get_for(instance):
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/manager.py", line 27, in filter
    for data in self._interaction.get_all(*args, include=self._model._get_embedded_fields(), **kwargs):
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 112, in get_all
    for data in self._all(self._get_path(), include=include, query=query, filters=filters, order=order):
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 77, in _all
    response, _ = self._list(
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 72, in _list
    return self.request("get", path, params=params, include=include)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 57, in request
    return self._request(method, path, data=data, params=params, headers=headers)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 36, in _request
    headers.update(self.get_headers())
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 25, in get_headers
    headers.update(self._get_auth_headers())
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 29, in _get_auth_headers
    return {"Authorization": "Bearer " + self._token_manager.get_access_token()}
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/tokens.py", line 154, in get_access_token
    if self._is_expire(token):
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/amocrm/v2/tokens.py", line 161, in _is_expire
    token_data = jwt.decode(token, options={"verify_signature": False})
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/jwt/api_jwt.py", line 104, in decode
    self._validate_claims(payload, merged_options, **kwargs)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/jwt/api_jwt.py", line 140, in _validate_claims
    self._validate_aud(payload, audience)
  File "/home/danilax86/diskD/PyCharmProjects/dialogflow/venv/lib/python3.9/site-packages/jwt/api_jwt.py", line 189, in _validate_aud
    raise InvalidAudienceError('Invalid audience')
jwt.exceptions.InvalidAudienceError: Invalid audience

Конфигурация токенов, как в примере:

tokens.default_token_manager(
    client_id = app.config['AMOCRM_INTEGRATION_ID'],
    client_secret = app.config['AMOCRM_SECRET'],
    subdomain = app.config['AMOCRM_DOMAIN'],
    redirect_url = 'https://36434e2604eb.ngrok.io',
    storage = tokens.FileTokensStorage()
)
tokens.default_token_manager.init(
    code = app.config['AMOCRM_AUTH'],
    skip_error = True
)
danilax86 commented 3 years ago

Это дубликат) Извини. Нужно всего лишь было обновить jwt