Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON parsing error when calling :GetMedia on the :kinesis-video-media API #174

Closed
dabrazhe opened this issue Feb 23, 2021 · 3 comments
Closed

Comments

@dabrazhe
Copy link

Dependencies

:dependencies 
                 [com.cognitect.aws/api "0.8.484"]
                 [com.cognitect.aws/endpoints "1.1.11.914"]
                 [com.cognitect.aws/kinesisvideo "796.2.665.0"]
                 [com.cognitect.aws/kinesis-video-media "770.2.568.0"]

Steps to reproduce

Create a stream in the Kinesis Video Streams console. There's no need to send media to the stream, a successful API call should return an empty fragment.

Call the Kinesis Video API to retrieve the endpoint and KVS stream arn.

(def kvs (aws/client {:api :kinesisvideo :region "eu-west-1" :credentials-provider (cred/profile-credentials-provider "devpl2")}))

; get the arn of the first stream in the KVSs
(def stream-arn
  (-> (aws/invoke kvs {:op :ListStreams :request {}})
      :StreamInfoList
      (first)
      :StreamARN))

(def kvs-endpoint (:DataEndpoint (aws/invoke kvs {:op :GetDataEndpoint
                                                  :request {:APIName "GET_MEDIA"
                                                            :StreamARN stream-arn}})))

;; Create a KV Media client.

(def kvmedia (aws/client {:api :kinesis-video-media :region "eu-west-1" :endpoint kvs-endpoint :credentials-provider (cred/profile-credentials-provider "devpl2")}))

Invoke the API.

(aws/invoke kvmedia {:op :GetMedia
                     :request {:StartSelector {:StartSelectorType "EARLIEST"}
                               :StreamARN stream-arn}})

Stack trace

The invoke method fails with the stack trace. Actually, any call of the :GetMedia operation results in the json error.

{:cognitect.anomalies/category :cognitect.anomalies/fault
 :cognitect.aws.client/throwable
 #error
  {:cause "JSON error (unexpected character): <"
   :trace
   [[clojure.data.json$_read invokeStatic "json.clj"
     230]
    [clojure.data.json$_read invoke "json.clj" 181]
    [clojure.data.json$read invokeStatic "json.clj" 276]
    [clojure.data.json$read doInvoke "json.clj" 232]
    [clojure.lang.RestFn applyTo "RestFn.java" 139]
    [clojure.core$apply invokeStatic "core.clj" 667]
    [clojure.core$apply invoke "core.clj" 660]
    [clojure.data.json$read_str invokeStatic "json.clj"
     282]
    [clojure.data.json$read_str doInvoke "json.clj" 278]
    [clojure.lang.RestFn invoke "RestFn.java" 439]
    [cognitect.aws.protocols.common$json_parse_error
     invokeStatic "common.clj" 42]
    [cognitect.aws.protocols.common$json_parse_error
     invoke "common.clj" 40]
    [cognitect.aws.protocols.rest$parse_http_response
     invokeStatic "rest.clj" 261]
    [cognitect.aws.protocols.rest$parse_http_response
     invoke "rest.clj" 249]
    [cognitect.aws.protocols.rest_json$eval15427$fn__15428
     invoke "rest_json.clj" 61]
    [clojure.lang.MultiFn invoke "MultiFn.java" 239]
    [cognitect.aws.client$handle_http_response
     invokeStatic "client.clj" 48]
    [cognitect.aws.client$handle_http_response invoke
     "client.clj" 43]
    [cognitect.aws.client$send_request$fn__12219$state_machine__6619__auto____12246$fn__12249
     invoke "client.clj" 111]
    [cognitect.aws.client$send_request$fn__12219$state_machine__6619__auto____12246
     invoke "client.clj" 107]
    [clojure.core.async.impl.ioc_macros$run_state_machine
     invokeStatic "ioc_macros.clj" 978]
    [clojure.core.async.impl.ioc_macros$run_state_machine
     invoke "ioc_macros.clj" 977]
    [clojure.core.async.impl.ioc_macros$run_state_machine_wrapped
     invokeStatic "ioc_macros.clj" 982]
    [clojure.core.async.impl.ioc_macros$run_state_machine_wrapped
     invoke "ioc_macros.clj" 980]
    [clojure.core.async.impl.ioc_macros$take_BANG_$fn__6637
     invoke "ioc_macros.clj" 991]
    [clojure.core.async.impl.channels.ManyToManyChannel$fn__623$fn__624
     invoke "channels.clj" 95]
    [clojure.lang.AFn run "AFn.java" 22]
    [java.util.concurrent.ThreadPoolExecutor runWorker
     "ThreadPoolExecutor.java" 1130]
    [java.util.concurrent.ThreadPoolExecutor$Worker run
     "ThreadPoolExecutor.java" 630]
    [clojure.core.async.impl.concurrent$counted_thread_factory$reify__492$fn__493
     invoke "concurrent.clj" 29]
    [clojure.lang.AFn run "AFn.java" 22]
    [java.lang.Thread run "Thread.java" 832]]
   :via [{:at [clojure.data.json$_read invokeStatic
               "json.clj" 230]
          :message "JSON error (unexpected character): <"
          :type java.lang.Exception}]}}
@dchelimsky dchelimsky added this to Inbox in AWS API Project Jun 14, 2021
@scottbale
Copy link
Collaborator

I am able to reproduce this issue both with the indicated dependency versions and with the latest versions.

@scottbale
Copy link
Collaborator

@dabrazhe thanks for opening this issue ... [checks notes] ... 19 months ago.

You should be able to accomplish what you're trying to do with a slight correction to the kvmedia def:

(def kvmedia 
 (aws/client 
  {:api :kinesis-video-media 
   :region "eu-west-1" 
   ;; :endpoint kvs-endpoint 
   :endpoint-override    {:hostname (str/replace kvs-endpoint #"https:\/\/" "")}
   :credentials-provider (cred/profile-credentials-provider "devpl2")}))

I've opened #218 to address the fact that AWS unexpectedly returned an XML response body when this library was expecting a JSON response, resulting in the JSON parsing error you found.

@dchelimsky
Copy link
Contributor

Fixed in release 0.8.603.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants