Comments (4)
This issue may be related to ZLib/GZip. Not sure. The workaround is to ask RestClient to send "Accept-Encoding: identity" header instead of its default "Accept-Encoding: gzip, deflate"
from mailjet-gem.
I traced this issue into RestClient::Request#decode. I dumped the "body" param to a base64 string and I used it to check whether the problem is in RestClient, Ruby, ZLib or MailJet v3 API.
To dump the "body" buffer I used RubyMine debugger, used the "Evaluate Expression" function and I evaluated Base64.strict_encode64(body)
The resulting string is : H4sIAAAAAAAAA6pWUHItKsov8sxLy1dSsFJQUtKBivimFhcnpqeCBf2TslKTSxTy8ksU0vJL81JAioJLEktKi53zU8BKTAxMFGoBAAA=
Then I wrote this very simple program :
require 'base64'
require 'zlib'
require 'stringio'
puts "RUBY_VERSION: #{RUBY_VERSION}"
puts "ZLib version: #{Zlib.zlib_version}"
DATA = "H4sIAAAAAAAAA6pWUHItKsov8sxLy1dSsFJQUtKBivimFhcnpqeCBf2TslKTSxTy8ksU0vJL81JAioJLEktKi53zU8BKTAxMFGoBAAA="
puts "\nBase64 string\n#{DATA}\n"
buffer = Base64.strict_decode64(DATA)
puts "\nRaw buffer\n#{buffer}\n\n"
gz = Zlib::GzipReader.new(StringIO.new(buffer))
begin
puts "\nZlib::GzipReader.new(StringIO.new(buffer)).read"
puts gz.read
rescue Exception => e
puts e
end
puts "\nZlib::GzipReader.new(StringIO.new(buffer)).read(77)"
puts gz.read(77)
puts "\nUsing Unix tools (base64 + gunzip)"
puts `echo #{DATA} | base64 --decode | gunzip -c - 2>&1`
Which outputs :
RUBY_VERSION: 2.1.2
ZLib version: 1.2.8
Base64 string
H4sIAAAAAAAAA6pWUHItKsov8sxLy1dSsFJQUtKBivimFhcnpqeCBf2TslKTSxTy8ksU0vJL81JAioJLEktKi53zU8BKTAxMFGoBAAA=
Raw buffer
���VPr-*�/��K�WR�RPRҁ�����'������R�K���K���K�R@��K�KJ���S�JL
L�j�
Zlib::GzipReader.new(StringIO.new(buffer)).read
unexpected end of file
Zlib::GzipReader.new(StringIO.new(buffer)).read(77)
{ "ErrorInfo" : "", "ErrorMessage" : "Object not found", "StatusCode" : 404 }
Using Unix tools (base64 + gunzip)
{ "ErrorInfo" : "", "ErrorMessage" : "Object not found", "StatusCode" : 404 }
gzip: stdin: unexpected end of file
So I suspect the MailJet server to return invalid GZip encoded data but at the same time, the same request run with curl works as expected :
curl -s -X GET --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" https://api.mailjet.com/v3/REST/contactslist/42
{ "ErrorInfo" : "", "ErrorMessage" : "Object not found", "StatusCode" : 404 }
But the same request with wget never output anything (nor print any error message) 👍
wget -d --http-user $MJ_APIKEY_PUBLIC --http-password=$MJ_APIKEY_PRIVATE -O result.json --header "Accept: application/json" --header "Accept-Encoding: gzip" https://api.mailjet.com/v3/REST/contactslist/42
The result.json file remains empty.
from mailjet-gem.
I made another change to the Mailjet::Resource code to force deflate encoding instead of gzip and it works like a charm ! (I'll push these changes to my fork for those interrested)
from mailjet-gem.
Fixed!
from mailjet-gem.
Related Issues (20)
- FATAL -- : [12421295-5b4a-4afa-828e-166f88779600] Net::OpenTimeout (execution expired): HOT 2
- Random 404 Errors HOT 1
- undefined method `merge' for nil:NilClass HOT 1
- Autoloading and Reloading Constants HOT 1
- error 400 while sending HOT 1
- Send a mail with template: error in template language HOT 1
- Rails integration causes an "Initialization autoloaded the constants ActionText::ContentHelper" warning HOT 1
- ActionMailer + Campaigns? HOT 1
- formatted_payload in resource.rb returns incomplete hash HOT 1
- Cannot change delivery method options after initialization of APIMailer HOT 2
- Setting `from` and `reply_to` to `nil` or `''` causes 400 Bad Request HOT 1
- Support for API v4 - SMS API HOT 2
- Possible bug in the `Mailjet::Send.create` method HOT 1
- Read only attribute causing NoMethodError (undefined method `map' for nil:NilClass) HOT 2
- I'm facing the same issue with just a basic hello world email template. HOT 1
- How to use Send API v3.1 and REST API v3 at the same time? HOT 1
- Remove password and API key from exception
- YAJL/json_gem replaces `JSON` in the whole application (not only in the mailjet-gem's context) HOT 2
- Issues using this gem outside of Rails HOT 1
- Ruby on Rails webhook not receiving any events notification
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailjet-gem.