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

GZip deflate causing JSON parse error when using gem #58

Closed
KNejad opened this issue Nov 9, 2017 · 2 comments
Closed

GZip deflate causing JSON parse error when using gem #58

KNejad opened this issue Nov 9, 2017 · 2 comments

Comments

@KNejad
Copy link

KNejad commented Nov 9, 2017

To reproduce

  1. Have a list containing 8 SmartMail templates (this is over 1KB of content for us)
  2. Call this method
      CreateSend::Transactional::SmartEmail.list(
        { api_key: Rails.application.secrets.campaignmonitor_api_key },
        clientID: Rails.application.secrets.campaignmonitor_client_id
      )

This crashes with

JSON::ParserError: 765: unexpected token at '���'
…d/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/common.rb:  156:in `parse'
…d/bundle/ruby/2.3.0/gems/json-2.1.0/lib/json/common.rb:  156:in `parse'
…ruby/2.3.0/gems/httparty-0.15.6/lib/httparty/parser.rb:  123:in `json'
…ruby/2.3.0/gems/httparty-0.15.6/lib/httparty/parser.rb:  143:in `parse_supported_format'
…ruby/2.3.0/gems/httparty-0.15.6/lib/httparty/parser.rb:  108:in `parse'
…ruby/2.3.0/gems/httparty-0.15.6/lib/httparty/parser.rb:   67:in `call'
…uby/2.3.0/gems/httparty-0.15.6/lib/httparty/request.rb:  382:in `parse_response'
…uby/2.3.0/gems/httparty-0.15.6/lib/httparty/request.rb:  350:in `block in handle_response'
…by/2.3.0/gems/httparty-0.15.6/lib/httparty/response.rb:   25:in `parsed_response'
…by/2.3.0/gems/httparty-0.15.6/lib/httparty/response.rb:   88:in `method_missing'
…send-4.1.1/lib/createsend/transactional_smart_email.rb:    9:in `list'
…1109093951/app/controllers/my_controller.rb:   63:in `block in get_campaign_monitor_autoresponders_list'

We have investigated this and the below HTTParty call is what the gem is roughly doing based on this line:
https://github.com/campaignmonitor/createsend-ruby/blob/master/lib/createsend/createsend.rb#L220
And the line that sets the header is: https://github.com/campaignmonitor/createsend-ruby/blob/master/lib/createsend/createsend.rb#L118

r = HTTParty.get("https://api.createsend.com/api/v3.1/transactional/smartemail", {headers: { "Accept-Encoding" => "gzip, deflate"}, query: options, basic_auth: { username: Rails.application.secrets.campaignmonitor_api_key, password: 'x'}})
r.body => #Still GZipped content. JSON cannot parse this!

Expected:

r = HTTParty.get("https://api.createsend.com/api/v3.1/transactional/smartemail", {query: options, basic_auth: { username: Rails.application.secrets.campaignmonitor_api_key, password: 'x'}})
r.body => # String encoded JSON that parses just fine!
@cmtiml
Copy link
Contributor

cmtiml commented Nov 27, 2017

Hello @KNejad,

We have merged the change for removing "Accept-Encoding"=>"gzip, deflate" and released it now for version 4.1.2 (https://rubygems.org/gems/createsend).

Please kindly check and verify if it solved the issue.
Thank you very much for your solution to the issue.

@cmtiml cmtiml closed this as completed Nov 27, 2017
@KNejad
Copy link
Author

KNejad commented Nov 28, 2017

Hello @cmtiml Yes this solved the issue we had. Thank you! :)

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

No branches or pull requests

2 participants