You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I think this is actually a Ruby / Net::HTTP issue but I thought I'd post this here in case other people run into the same problem. Here's the issue I opened on the Ruby issue tracker ( https://bugs.ruby-lang.org/issues/15472 ):
It seems that invalid (JSON) data is being sent once the request's body passes a size threshold. I'm sending emails via the sparkpost.com API using the sparkpost_rails gem ( https://github.com/the-refinery/sparkpost_rails ). That gem uses Net::HTTP to make its API calls.
I upgraded my app from Ruby 2.5.3 to Ruby 2.6.0 on December 25th. Yesterday, on the 26th, my app attempted to send its nightly emails to users. I was flooded with these errors from the API:
{ "errors": [ { "message": "invalid data format\/type", "description": "Problems parsing request as json", "code": "1300" } ] }
After some debugging / trial & error I discovered that the length of the email messages seemed to be the problem. I haven't nailed down the exact maximum length that will work but I know that if the request body is 16,511 characters long the message will be sent. If it's 17,396 characters it will fail.
I've also tried replacing Net::HTTP with the rest_client gem. The full-sized messages get sent with no problems using RestClient.
def post_to_api
url = "https://api.sparkpost.com/api/v1/transmissions"
RestClient.post(url, JSON.generate(@data), @headers)
end
and my (full-length, much larger than 17,396 characters) messages get sent with no problem.
I also tried logging the actual HTTP requests using the httplog gem (https://github.com/trusche/httplog) in Ruby 2.5.3 and 2.6.0. Unfortunately that showed the request payloads were identical. But I suspect that gem's logging does some conversion that isn't actually happening in the real data being sent to the SparkPost API.
The text was updated successfully, but these errors were encountered:
MSeneadza
added a commit
to MSeneadza/sparkpost_rails
that referenced
this issue
Dec 27, 2018
So I think this is actually a Ruby / Net::HTTP issue but I thought I'd post this here in case other people run into the same problem. Here's the issue I opened on the Ruby issue tracker ( https://bugs.ruby-lang.org/issues/15472 ):
It seems that invalid (JSON) data is being sent once the request's body passes a size threshold. I'm sending emails via the sparkpost.com API using the sparkpost_rails gem ( https://github.com/the-refinery/sparkpost_rails ). That gem uses Net::HTTP to make its API calls.
I upgraded my app from Ruby 2.5.3 to Ruby 2.6.0 on December 25th. Yesterday, on the 26th, my app attempted to send its nightly emails to users. I was flooded with these errors from the API:
After some debugging / trial & error I discovered that the length of the email messages seemed to be the problem. I haven't nailed down the exact maximum length that will work but I know that if the request body is 16,511 characters long the message will be sent. If it's 17,396 characters it will fail.
I've also tried replacing Net::HTTP with the rest_client gem. The full-sized messages get sent with no problems using RestClient.
So I can replace this (https://github.com/the-refinery/sparkpost_rails/blob/master/lib/sparkpost_rails/delivery_method.rb#L379):
with
and my (full-length, much larger than 17,396 characters) messages get sent with no problem.
I also tried logging the actual HTTP requests using the httplog gem (https://github.com/trusche/httplog) in Ruby 2.5.3 and 2.6.0. Unfortunately that showed the request payloads were identical. But I suspect that gem's logging does some conversion that isn't actually happening in the real data being sent to the SparkPost API.
The text was updated successfully, but these errors were encountered: