Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
3 years ago

Conectarse a la API en Power Query - Error: la longitud del bloque no coincide con su complemento.

Hola

Estoy intentando conectarme a Free Open-Source Weather API | Open-Meteo.com a través de una nueva consulta. Puedo ver el archivo json en https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m
He mirado los temas existentes sobre esto, este es el código que probé:

let
Source = Json.Document(Web.Contents("https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m")),
Table = Table.FromRows(Source),
PromotedHeaders = Table.PromoteHeaders(Table)
in
PromotedHeaders

También intenté usar Binary.Decompress() pero no funcionó. Cualquier ayuda sería muy apreciada. Gracias


Este es el error que recibo:

Error inesperado: La longitud del bloque no coincide con su complemento.
Detalles:
Microsoft.Mashup.Evaluator.Interface.ErrorException: La longitud del bloque no coincide con su complemento. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: la longitud del bloque no coincide con su complemento. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: la longitud del bloque no coincide con su complemento. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: la longitud del bloque no coincide con su complemento. ---> Microsoft.Mashup.Evaluator.Interface.ErrorException: la longitud del bloque no coincide con su complemento. ---> System.IO.InvalidDataException: la longitud del bloque no coincide con su complemento. ---> System.IO.InvalidDataException: la longitud del bloque no coincide con su complemento.
en System.IO.Mashup.Compression.Inflater.DecodeUncompressedBlock(Boolean& end_of_block)
en System.IO.Mashup.Compression.Inflater.Decode()
en System.IO.Mashup.Compression.Inflater.Inflate(Byte[] bytes, desplazamiento Int32, longitud Int32)
en System.IO.Mashup.Compression.DeflateStream.Read(Matriz Byte[], desplazamiento Int32, recuento de Int32)
en Microsoft.Mashup.Engine1.Library.Http.Response.RetryingWebResponseStream.Read(Búfer de bytes[], desplazamiento Int32, recuento de Int32)
en Microsoft.Mashup.Engine1.Library.Http.ErrorLoggingReadStream.Read(Búfer de bytes[], desplazamiento Int32, recuento de Int32)
en Microsoft.Mashup.Common.StreamExtensions.ConcatStream.Read(búfer Byte[], desplazamiento Int32, recuento de Int32)
en Microsoft.Mashup.Engine1.Library.PersistentCacheExtensions.CachingStream.Read(Búfer de bytes[], desplazamiento Int32, recuento de Int32)
en System.IO.StreamReader.ReadBuffer(Char[] userBuffer, Int32 userOffset, Int32 desiredChars, Boolean& readToUserBuffer)
en System.IO.StreamReader.Read(búfer Char[], índice Int32, recuento Int32)
en Microsoft.Mashup.Engine1.Library.Json.JsonTokenizer.FillBuffer(Int32 bufferPosition, Int32 minimumCount)
en Microsoft.Mashup.Engine1.Library.Json.JsonParser.Parse(lector de TextReader, valor de valor)
en Microsoft.Mashup.Engine1.Library.Json.JsonModule.Json.DocumentFunctionValue.TypedInvoke(Value jsonText, Value encoding)
en Microsoft.Mashup.Engine1.Runtime.NativeFunctionValue2'3.Invoke(Value arg0, Value arg1)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.InstructionInvocationInstruction2.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(índice Int32)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(índice Int32)
en Microsoft.Mashup.Engine1.Language.InstructionInvocationInstruction1.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.InstructionInvocationInstruction2.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(índice Int32)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(índice Int32)
en Microsoft.Mashup.Engine1.Language.InstructionInvocationInstruction1.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.InstructionInvocationInstruction2.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(índice Int32)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(índice Int32)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(índice Int32)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(índice Int32)
en Microsoft.Mashup.Engine1.Runtime.Library.Linker.BindFunctionValue.TypedInvoke(entorno RecordValue, Value , nombre TextValue)
en Microsoft.Mashup.Engine1.Runtime.NativeFunctionValue3'4.Invoke(Value arg0, Value arg1, Value arg2)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue0.Invoke()
en Microsoft.Mashup.Engine1.Language.ListInstruction.RuntimeListValue.Force(índice Int32)
en Microsoft.Mashup.Engine1.Language.ListInstruction.RuntimeListValue.get_Item(índice Int32)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(índice Int32)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(índice Int32)
en Microsoft.Mashup.Engine1.Language.FunctionInvocationInstruction2.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.Instruction.ExecuteCondition(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.ExecuteCondition(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.IfInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.DebugInstruction.Execute(MembersFrame1& frame)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue1.Invoke(Value arg0)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.Force(índice Int32)
en Microsoft.Mashup.Engine1.Language.RecordInstruction.RuntimeRecordValue.get_Item(índice Int32)
en Microsoft.Mashup.Engine1.Language.MembersFunctionValue0.Invoke()
en Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(parámetros DocumentEvaluationParameters, devolución de llamada Action'1)
--- Fin del --- de seguimiento de la pila de excepciones internas
en Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(parámetros DocumentEvaluationParameters, devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(parámetros DocumentEvaluationParameters, devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.FirewallPartition.BeginGetResult[T](devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.FirewallDocumentEvaluator.Evaluation'1.OnBufferComplete(excepción de excepción)
en Microsoft.Mashup.Evaluator.Firewall.BeginBufferPartitions(Action'1 callback)
en Microsoft.Mashup.Evaluator.FirewallDocumentEvaluator.BeginGetResultInternal[T](parámetros DocumentEvaluationParameters, devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.Interface.IDocumentEvaluatorExtensions.GetResult[T](IDocumentEvaluator'1 evaluator, parámetros DocumentEvaluationParameters)
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetResult[T](canal IMessageChannel, mensaje BeginGetResultMessage, acción Action'1)
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetPreviewValueSource(IMessageChannel channel, mensaje BeginGetPreviewValueSourceMessage)
en Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.OnMessageWithUnknownChannel(IMessageChannel baseChannel, MessageWithUnknownChannel messageWithUnknownChannel)
en Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.EvaluationHost.Run()
en Microsoft.Mashup.Container.EvaluationContainerMain.Run(Object args)
en Microsoft.Mashup.Evaluator.SafeThread2.<>c__DisplayClass9_0.b__0(Objeto o)
en Microsoft.Mashup.Container.EvaluationContainerMain.SafeRun(String[] args)
en Microsoft.Mashup.Container.EvaluationContainerMain.Main(String[] args)
--- Fin del --- de seguimiento de la pila de excepciones internas
en Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.<>c__DisplayClass3_0.b__0(Resultado de evaluación2'1)
--- Fin del --- de seguimiento de la pila de excepciones internas
en Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.<>c__DisplayClass3_0.b__0(Resultado de evaluación2'1)
en Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(parámetros DocumentEvaluationParameters, devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.BeginGetResult(parámetros DocumentEvaluationParameters, devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.FirewallPartition.BeginGetResult[T](devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.FirewallDocumentEvaluator.Evaluation'1.OnBufferComplete(excepción de excepción)
en Microsoft.Mashup.Evaluator.Firewall.BeginBufferPartitions(Action'1 callback)
en Microsoft.Mashup.Evaluator.FirewallDocumentEvaluator.BeginGetResultInternal[T](parámetros DocumentEvaluationParameters, devolución de llamada Action'1)
en Microsoft.Mashup.Evaluator.Interface.IDocumentEvaluatorExtensions.GetResult[T](IDocumentEvaluator'1 evaluator, parámetros DocumentEvaluationParameters)
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetResult[T](canal IMessageChannel, mensaje BeginGetResultMessage, acción Action'1)
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetPreviewValueSource(IMessageChannel channel, mensaje BeginGetPreviewValueSourceMessage)
en Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.OnMessageWithUnknownChannel(IMessageChannel baseChannel, MessageWithUnknownChannel messageWithUnknownChannel)
en Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.EvaluationHost.Run()
en Microsoft.Mashup.Container.EvaluationContainerMain.Run(Object args)
en Microsoft.Mashup.Evaluator.SafeThread2.<>c__DisplayClass9_0.b__0(Objeto o)
en Microsoft.Mashup.Container.EvaluationContainerMain.SafeRun(String[] args)
en Microsoft.Mashup.Container.EvaluationContainerMain.Main(String[] args)
--- Fin del --- de seguimiento de la pila de excepciones internas
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.<>c__DisplayClass9_1.b__1()
en Microsoft.Mashup.Evaluator.RemotePreviewValueSource.<>c__DisplayClass0_0.b__0()
en Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(String entryName, IEngineHost engineHost, IMessageChannel channel, Action action)
--- Fin del --- de seguimiento de la pila de excepciones internas
en Microsoft.Mashup.Evaluator.EvaluationHost.<>c__DisplayClass17_0.b__1()
en Microsoft.Mashup.Common.SafeExceptions.IgnoreSafeExceptions(host IEngineHost, seguimiento de IHostTrace, acción de acción)
en Microsoft.Mashup.Evaluator.EvaluationHost.TryReportException(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, excepción de excepción)
en Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(String entryName, IEngineHost engineHost, IMessageChannel channel, Action action)
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.<>c__DisplayClass12_1'1.b__0()
en Microsoft.Mashup.Evaluator.EvaluationHost.ReportExceptions(IHostTrace trace, IEngineHost engineHost, IMessageChannel channel, acción de acción)
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetResult[T](canal IMessageChannel, mensaje BeginGetResultMessage, acción Action'1)
en Microsoft.Mashup.Evaluator.RemoteDocumentEvaluator.Service.OnBeginGetPreviewValueSource(IMessageChannel channel, mensaje BeginGetPreviewValueSourceMessage)
en Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.OnMessageWithUnknownChannel(IMessageChannel baseChannel, MessageWithUnknownChannel messageWithUnknownChannel)
en Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.EvaluationHost.Run()
en Microsoft.Mashup.Container.EvaluationContainerMain.Run(Object args)
en Microsoft.Mashup.Evaluator.SafeThread2.<>c__DisplayClass9_0.b__0(Objeto o)
en Microsoft.Mashup.Container.EvaluationContainerMain.SafeRun(String[] args)
en Microsoft.Mashup.Container.EvaluationContainerMain.Main(String[] args)
--- Fin del --- de seguimiento de la pila de excepciones internas
en Microsoft.Mashup.Evaluator.EvaluationHost.OnException(IEngineHost engineHost, IMessageChannel channel, ExceptionMessage message)
en Microsoft.Mashup.Evaluator.MessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.ChannelMessenger.ChannelMessageHandlers.TryDispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.MessageHandlers.Dispatch(canal IMessageChannel, mensaje de mensaje)
en Microsoft.Mashup.Evaluator.Interface.IMessageChannelExtensions.WaitFor[T](IMessageChannel channel)
en Microsoft.Mashup.Evaluator.RemotePreviewValueSource.PreviewValueSource.WaitFor(Func'1 condition, Boolean disposing)
en Microsoft.Mashup.Evaluator.RemotePreviewValueSource.PreviewValueSource.get_TableSource()
en Microsoft.Mashup.Evaluator.Interface.TracingPreviewValueSource.get_TableSource()
en Microsoft.Mashup.Host.Document.Analysis.PackageDocumentAnalysisInfo.PackagePartitionAnalysisInfo.SetPreviewValue(EvaluationResult2'1 result, Func'1 getStaleSince, Func'1 getSampled)

11 Replies

  • El error anterior es causado por que los datos de su La API se almacena como un documento JSON comprimido, que se reconoce como formato no válido en Power BI Desktop.

    En su escenario, puede usar Power Query para recuperar datos de su API y usar la función Binary.Decompress() para extraer los datos.

    Para obtener más detalles sobre cómo recuperar datos de API en Power Query, revise este hilo.

    Para obtener más detalles sobre cómo usar la función Binary.Decompress(), revise este blog: Trabajar con compresión en Power Query y Power BI Desktop.

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      Había visto el hilo que mencionaste y esto es exactamente lo que he intentado.

      También había visto la publicación del blog sobre la función Binary.Decompress() que intenté incorporar pero aún así no funcionó.

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      ¡Gracias!

      Ambas opciones funcionaron muy bien. Realmente lo aprecio.

      • Syndicate_Admin's avatar
        Syndicate_Admin
        Icon for Administrator rankAdministrator

        Incluso si el error es el mismo, este es un problema ligeramente diferente: los enlaces en esta página en realidad devuelven archivos zip, y lo que es más, los archivos zip contienen varios archivos. Debe usar la API para devolver los datos directamente, por ejemplo, en formato JSON, como se describe en la sección "Formato de salida" aquí. Aquí hay un ejemplo rápido:

        let
            Source = Json.Document(Web.Contents("http://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?format=json")),
            #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
            #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type any}}),
            Column1 = #"Changed Type"{1}[Column1],
            #"Converted to Table1" = Table.FromList(Column1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
            #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table1", "Column1", {"indicator", "country", "countryiso3code", "date", "value", "unit", "obs_status", "decimal"}, {"Column1.indicator", "Column1.country", "Column1.countryiso3code", "Column1.date", "Column1.value", "Column1.unit", "Column1.obs_status", "Column1.decimal"}),
            #"Expanded Column1.country" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.country", {"id", "value"}, {"Column1.country.id", "Column1.country.value"}),
            #"Expanded Column1.indicator" = Table.ExpandRecordColumn(#"Expanded Column1.country", "Column1.indicator", {"id", "value"}, {"Column1.indicator.id", "Column1.indicator.value"})
        in
            #"Expanded Column1.indicator"
  • Hola Chris, acabo de leer tus 2 blogs RE "dinámico what-if", excelente como siempre. Mi pregunta: ¿hay una opción directa en PQ para cambiar Import/DQ, en lugar de volver a PBI? En varias ocasiones me refería a DQ, pero terminé importando, no hay forma de volver atrás una vez que se importa en PBI. Lo siento, quería publicar en tu blog, pero Akismet seguía bloqueándome.

  • Lo siento + 1 pregunta más: ¿cómo puedo pasar la misma variable dos veces en la función Web.Contents? En el ejemplo siguiente, var "daily" se pasó dos veces, pero PQ da un error para "Query = [ daily = "temperature_2m_min", "_max"] , si uso var diario en una 2ª línea, PQ también da un error de que var ya está definido en el ámbito ---------- " https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&daily=temperature_2m_max&daily=temperature_2m_min&daily=sunrise&daily=sunset&temperature_unit=celsius&windspeed_unit=kmh&precipitation_unit=mm&timeformat=iso8601&past_days=0&forecast_days=3&start_date=2023-04-09&end_date=2023-04-11&timezone=GMT"