K1llMan / Yandex.Music.Api

Yandex.Music API (Unofficial) for .Net
GNU General Public License v3.0
91 stars 19 forks source link

Ошибка десериализации при создании сессии #35

Closed WayneHarsman closed 7 months ago

WayneHarsman commented 7 months ago

Описание ошибки:

При вызове метода CreateAuthSession(AuthStorage storage, string userName) возникает исключение внутри CommonRequestProvider в методе GetDataFromResponseAsync<T>. Массив методов авторизации в ответе на запрос содержит в себе элемент "social_gg" десериализация которого текущей версией API не предусмотренна. Ошибка предположительно возникает только при выполнении запросов с IP аддресов находящихся не на территории РФ.

Часть ответа на запрос создания сессии: image

StackTrace:

System.Exception: Ошибка десериализации Newtonsoft.Json.JsonSerializationException: Error converting value "social_gg" to type 'Yandex.Music.Api.Models.Account.YAuthMethod'. Path 'auth_methods[3]', line 1, position 298.
 ---> System.ArgumentException: Requested value 'social_gg' was not found.
   at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   --- End of inner exception stack trace ---
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Yandex.Music.Api.Common.Providers.CommonRequestProvider.GetDataFromResponseAsync[T](YandexMusicApi api, HttpResponseMessage response)
   at Yandex.Music.Api.Common.Providers.CommonRequestProvider.GetDataFromResponseAsync[T](YandexMusicApi api, HttpResponseMessage response) in C:\Users\Wayne Harsman\Documents\Programming\Projects\KA.YandexMusicApi\src\Yandex.Music.Api\Common\Providers\CommonRequestProvider.cs:line 61
   at Yandex.Music.Api.Requests.Common.YRequest`1.GetResponseAsync() in C:\Users\Wayne Harsman\Documents\Programming\Projects\KA.YandexMusicApi\src\Yandex.Music.Api\Requests\Common\YRequest.cs:line 41
   at Yandex.Music.Api.API.YUserAPI.CreateAuthSessionAsync(AuthStorage storage, String userName) in C:\Users\Wayne Harsman\Documents\Programming\Projects\KA.YandexMusicApi\src\Yandex.Music.Api\API\YUserAPIAsync.cs:line 126
   at Yandex.Music.Api.API.YUserAPI.CreateAuthSession(AuthStorage storage, String userName) in C:\Users\Wayne Harsman\Documents\Programming\Projects\KA.YandexMusicApi\src\Yandex.Music.Api\API\YUserAPI.cs:line 43
   at Program.<Main>$(String[] args) in C:\Users\Wayne Harsman\Documents\Programming\Projects\YaMAPIQuickTest\Playground\YaMuApiPlayground\YaMuApiPlayground\Program.cs:line 9

Шаги к воссозданию ошибки

var api = new YandexMusicApi();
var storage = new AuthStorage();

api.User.CreateAuthSession(storage, "...actualLogin...");

Как указано выше, наличие елемента social_gg вероятнее всего связано с региональными ограничениями самого Яндекса

Возможное решение

Простейшим решением может быть модификация перечисления YAuthMethod следующим способом:

public enum YAuthMethod
    {
        Password,
        [EnumMember(Value = "magic_x_token")]
        MagicToken,
        [EnumMember(Value = "magic_link")]
        MagicLink,
        Magic,
        Otp,
        [EnumMember(Value = "social_gg")]
        Social
    }

Вариант рабочий

Предположительно игнорирование незнакомых типов будет более универсальным решением. Я не имею ни малейшего представления о том что из себя должен представлять данным метод авторизации т.к. веб интерфейс при ручном входе в аккаунт не имеет отличий от "родного славянского"

K1llMan commented 7 months ago

Это вход через социальные сети. Добавлю в перечисление.

K1llMan commented 7 months ago

Добавил версию 1.7.1.