При обращении на сайт яндекса для получения токена flask выдает ошибку 400 Bad Request

есть проблема. Делаю авторизацию через Яндекс ID на Flask. Хочу обменять код авторизации на OAuth токен. Делаю все по документации яндекса но при обращении на сайт не отдает токен и выдает ошибку 400 Bad request. Документация https://yandex.ru/dev/id/doc/dg/oauth/reference/auto-code-client.html#auto-code-client__get-token.

    def get_token_from_code(
    self, code: str, device_id: str | None = None,
    device_name: str | None = None
) -> Token:

    url = f'{self.BASE_URL}/token?{urlencode(self.__params)}'
    method = 'POST'
    data = {
        'grant_type': 'authorization_code',
        'code': code,
    }
    if device_id:
        try:
            DeviceID.validate(device_id)
        except InvalidDeviceID as e:
            self.log.error(e)
            raise e
        else:
            data['device_id'] = device_id
            if not device_name:
                warnings.warn(
                    'device_id is specified, but device_name is not. '
                    'Yandex ID returns token for unknown device.', UserWarning
                )
    if device_name:
        try:
            DeviceName.validate(device_name)
        except InvalidDeviceName as e:
            self.log.error(e)
            raise e
        else:
            data['device_name'] = device_name
            if not device_id:
                warnings.warn(
                    'device_name is specified, but device_id is not. '
                    'device_name will be ignored.', UserWarning
                )
    headers = {
        'Authorization': f'Basic {b64encode(f"{self._client_id}:{self._client_secret}".encode()).decode()}'
    }

    response = requests.post(url = url, data=data, headers=headers)
    response.raise_for_status()
    if 'error' in response:
        match response['error']:
            case 'authorization_pending':
                raise AuthorizationPending(response['error_description'])
            case 'bad_verification_code':
                raise BadVerificationCode(response['error_description'])
            case 'invalid_client':
                raise InvalidClient(response['error_description'])
            case 'invalid_grant':
                raise InvalidGrant(response['error_description'])
            case 'invalid_request':
                raise InvalidRequest(response['error_description'])
            case 'invalid_scope':
                raise InvalidScope(response['error_description'])
            case 'unauthorized_client':
                raise UnauthorizedClient(response['error_description'])
            case 'unsupported_grant_type':
                raise UnsupportedGrantType(response['error_description'])
            case _:
                raise YandexOAuthError(response['error_description'])

    return response.json()

Ответы (0 шт):