Krukov / amocrm_api

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

amocrm.v2.exceptions.NoToken: You need to init tokens with code by 'init' method #66

Closed foopy02 closed 2 years ago

foopy02 commented 2 years ago

Пытаюсь подключиться к api, но не получается

from amocrm.v2 import tokens
from amocrm.v2 import Contact, Company, Lead
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
tokens.default_token_manager(
    client_id="***",
    client_secret="***",
    subdomain="***",
    redirect_url="https://google.com/",
    storage=tokens.FileTokensStorage(directory_path=dir_path),  # by default FileTokensStorage
)
print(dir_path)
tokens.default_token_manager.init(code="***", skip_error=False)
leads = Lead.objects.all()
for lead in leads:
    print(lead)

raise exceptions.NoToken("You need to init tokens with code by 'init' method") amocrm.v2.exceptions.NoToken: You need to init tokens with code by 'init' method

Krukov commented 2 years ago

А вы redirect_url правильно указали ? как в интеграции в АМО? и лучше скиньте полный трейсбек потому что не понятно на какой стадии падает

Samolyotik commented 2 years ago

Такая же ошибка, redirect_url пробовал разные, указывал такие же как и в интеграции. Все ключи точно правильные

Traceback (most recent call last): File "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/crypto_newton/puzzle_amocrm/puzamo.py", line 12, in new_lead = Lead.objects.create(name="that_is_new_lead") File "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/venv/lib/python3.9/site-packages/amocrm/v2/manager.py", line 16, in create return self._model(data=self._interaction.create(data=data or kwargs)) File "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 123, in create response, status = self.request("post", self._get_path(), data=[data]) File "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/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 "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 36, in _request headers.update(self.get_headers()) File "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/venv/lib/python3.9/site-packages/amocrm/v2/interaction.py", line 25, in get_headers headers.update(self._get_auth_headers()) File "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/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 "/Users/andreykrypskiy/work/projects/CryptoNewtonDjango/venv/lib/python3.9/site-packages/amocrm/v2/tokens.py", line 153, in get_access_token raise exceptions.NoToken("You need to init tokens with code by 'init' method") amocrm.v2.exceptions.NoToken: You need to init tokens with code by 'init' method

Samolyotik commented 2 years ago

Разобрался, конкретно эта ошибка возникала из-за skip_error=False. Если убрать, то будет более подробная ошибка. Конкретно у меня была ошибка в subdomain