Async::REST::Error: Unknown content type: application/octet-stream! on reading from KV
dorongutman opened this issue · 6 comments
I have the following example code:
Cloudflare.connect(key: CLOUDFLARE_KEY, email: CLOUDFLARE_EMAIL) do |connection|
puts "we have a connection: #{connection}"
account = connection.accounts.to_a[0]
puts "account is: #{account}"
namespaces = account.kv_namespaces
puts "namespaces are: #{namespaces}"
namespace = namespaces.find_by_id(NAMESPACE_ID)
puts "namespace is: #{namespace}"
namespace.write_value('my-test', 'asd')
puts "value is: #{namespace.read_value('my-test')}"
end
Running it in rails c
gives the following:
we have a connection: #<Cloudflare::Connection:0x00005640ad3743c8>
account is: #<Cloudflare::Account:0x00005640a81dab70>
namespaces are: #<Cloudflare::KV::Namespaces:0x00005640a72ad6c0>
namespace is: #<Cloudflare::KV::Namespace:0x00005640a604f7d0>
error: Async::Task [oid=0x624d0] [pid=242] [2020-07-31 10:16:12 +0000]
| Async::REST::Error: Unknown content type: application/octet-stream!
| → /srv/vendor/bundle/ruby/2.7.0/gems/async-rest-0.10.1/lib/async/rest/wrapper/json.rb:75 in `process_response'
| /srv/vendor/bundle/ruby/2.7.0/gems/async-rest-0.10.1/lib/async/rest/representation.rb:67 in `process_response'
| /srv/vendor/bundle/ruby/2.7.0/gems/cloudflare-4.2.0/lib/cloudflare/representation.rb:82 in `process_response'
| /srv/vendor/bundle/ruby/2.7.0/gems/async-rest-0.10.1/lib/async/rest/representation.rb:80 in `block (2 levels) in <class
| /srv/vendor/bundle/ruby/2.7.0/gems/async-rest-0.10.1/lib/async/rest/representation.rb:92 in `value!'
| /srv/vendor/bundle/ruby/2.7.0/gems/async-rest-0.10.1/lib/async/rest/representation.rb:107 in `value'
| /srv/vendor/bundle/ruby/2.7.0/gems/cloudflare-4.2.0/lib/cloudflare/kv/namespaces.rb:39 in `read_value'
| (irb):256 in `block in irb_binding'
| /srv/vendor/bundle/ruby/2.7.0/gems/cloudflare-4.2.0/lib/cloudflare.rb:41 in `block in connect'
| /srv/vendor/bundle/ruby/2.7.0/gems/async-1.26.1/lib/async/task.rb:258 in `block in make_fiber'
It probably means that Cloudflare have changed their API and something is broken and returning a non-JSON error message.
You could try printing it out in lib/cloudflare/representation.rb:82 in 'process_response'
@ioquatix I don't think so, because using Postman (or plain old curl) returns successful results but the headers of the response still return as application/octet-stream
;
HTTP/1.1 200 OK
Date: Fri, 31 Jul 2020 12:35:27 GMT
Content-Type: application/octet-stream
Content-Length: 22
Connection: keep-alive
CF-Ray: REDACTED
Accept-Ranges: bytes
Cache-Control: no-store, no-cache, must-revalidate
CF-Cache-Status: DYNAMIC
cf-request-id: REDACTED
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
x-envoy-upstream-service-time: 209
Server: cloudflare
What is the content of the response, is it JSON?
in this specific case it's the string asd
(as you can see in the example code in the issue description), but it's the same results if it's a json string.
Ah I see so we should really allow a non-json response from this endpoint.