Krukov / amocrm_api

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

Создание сущностей #73

Closed nikolay17nsk closed 2 years ago

nikolay17nsk commented 2 years ago

Здравствуйте, не могу созадть сущность, токен возвращает. но сущность не создается from amocrm.v2.entity.contact import Contact from amocrm.v2 import tokens value = tokens.FileTokensStorage() print(value.get_access_token()) print(value.get_refresh_token())

Contact.objects.create(name = "test_009")

Ошибка => Traceback (most recent call last): File "C:\Users\Nikol\OneDrive\Рабочий стол\амоапи\345678.py", line 22, in Contact.objects.create(name = "Залупа") File "D:\успех\lib\site-packages\amocrm\v2\manager.py", line 16, in create return self._model(data=self._interaction.create(data=data or kwargs)) File "D:\успех\lib\site-packages\amocrm\v2\interaction.py", line 123, in create response, status = self.request("post", self._get_path(), data=[data]) File "D:\успех\lib\site-packages\amocrm\v2\interaction.py", line 57, in request return self._request(method, path, data=data, params=params, headers=headers) File "D:\успех\lib\site-packages\amocrm\v2\interaction.py", line 36, in _request headers.update(self.get_headers()) File "D:\успех\lib\site-packages\amocrm\v2\interaction.py", line 25, in get_headers headers.update(self._get_auth_headers()) File "D:\успех\lib\site-packages\amocrm\v2\interaction.py", line 29, in _get_auth_headers return {"Authorization": "Bearer " + self._token_manager.get_access_token()} File "D:\успех\lib\site-packages\amocrm\v2\tokens.py", line 151, in get_access_token token = self._storage.get_access_token() AttributeError: 'NoneType' object has no attribute 'get_access_token'

Подскажите, пожалуйста, в чем может быть проблема?

Krukov commented 2 years ago

В вашем коде неверно сделана инициализации сториджа для токена

from amocrm.v2 import tokens

tokens.default_token_manager(
    client_id="xxx-xxx-xxxx-xxxx-xxxxxxx",
    client_secret="xxxx",
    subdomain="subdomain",
    redirect_url="https://xxxx/xx",
    storage=tokens.FileTokensStorage(),  # by default FileTokensStorage
)
tokens.default_token_manager.init(code="..very long code...", skip_error=True)