GithubHelp home page GithubHelp logo

Comments (5)

solson avatar solson commented on August 16, 2024

@pawandubey Please paste the full stacktrace and the code you were running so we can investigate.

from bing_translator-gem.

pawandubey avatar pawandubey commented on August 16, 2024

@solson I am trying to use it from inside rails.

Gemfile:

gem 'bing_translator', '~> 4.5.0'

routes.rb

post '/translate' => 'application#translate'

application_controller.rb:

  def translate
    translate_text(params[:text])
  end

  private

  def translate_text(text)
    client_id = 'abc'
    client_secret = Rails.application.secrets[:microsoft][:translator]
    azure_key = Rails.application.secrets[:microsoft][:azure_key]
    translator = BingTranslator.new(client_id, client_secret, false, azure_key)

    translated_text = translator.translate(text, from: 'en', to: 'fr')

    render json: translated_text
  end

From the development log:

Started POST "/translate" for 127.0.0.1 at 2016-10-22 00:36:02 +0530
Processing by ApplicationController#translate as */*
  Parameters: {"text"=>"hello, world", "application"=>{"text"=>"hello, world"}}
Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)



BingTranslator::Exception (undefined method `encoding' for nil:NilClass):

app/controllers/application_controller.rb:49:in `translate_text'
app/controllers/application_controller.rb:13:in `translate'

From the response returned:

{
  "traces": {
    "Full Trace": [
      {
        "trace": "bing_translator (4.5.0) lib/bing_translator.rb:179:in `rescue in result'",
        "id": 0
      },
      {
        "trace": "bing_translator (4.5.0) lib/bing_translator.rb:173:in `result'",
        "id": 1
      },
      {
        "trace": "bing_translator (4.5.0) lib/bing_translator.rb:45:in `translate'",
        "id": 2
      },
      {
        "trace": "app/controllers/application_controller.rb:49:in `translate_text'",
        "id": 3
      },
      {
        "trace": "app/controllers/application_controller.rb:13:in `translate'",
        "id": 4
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'",
        "id": 5
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/base.rb:188:in `process_action'",
        "id": 6
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'",
        "id": 7
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'",
        "id": 8
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'",
        "id": 9
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'",
        "id": 10
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'",
        "id": 11
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'",
        "id": 12
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'",
        "id": 13
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'",
        "id": 14
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `block in instrument'",
        "id": 15
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'",
        "id": 16
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `instrument'",
        "id": 17
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'",
        "id": 18
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'",
        "id": 19
      },
      {
        "trace": "activerecord (5.0.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'",
        "id": 20
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/base.rb:126:in `process'",
        "id": 21
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal.rb:190:in `dispatch'",
        "id": 22
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal.rb:262:in `dispatch'",
        "id": 23
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'",
        "id": 24
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'",
        "id": 25
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'",
        "id": 26
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `each'",
        "id": 27
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'",
        "id": 28
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'",
        "id": 29
      },
      {
        "trace": "warden (1.2.6) lib/warden/manager.rb:35:in `block in call'",
        "id": 30
      },
      {
        "trace": "warden (1.2.6) lib/warden/manager.rb:34:in `catch'",
        "id": 31
      },
      {
        "trace": "warden (1.2.6) lib/warden/manager.rb:34:in `call'",
        "id": 32
      },
      {
        "trace": "rack (2.0.1) lib/rack/etag.rb:25:in `call'",
        "id": 33
      },
      {
        "trace": "rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'",
        "id": 34
      },
      {
        "trace": "rack (2.0.1) lib/rack/head.rb:12:in `call'",
        "id": 35
      },
      {
        "trace": "activerecord (5.0.0.1) lib/active_record/migration.rb:552:in `call'",
        "id": 36
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'",
        "id": 37
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'",
        "id": 38
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'",
        "id": 39
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'",
        "id": 40
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'",
        "id": 41
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'",
        "id": 42
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'",
        "id": 43
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'",
        "id": 44
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'",
        "id": 45
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'",
        "id": 46
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'",
        "id": 47
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'",
        "id": 48
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'",
        "id": 49
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'",
        "id": 50
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'",
        "id": 51
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'",
        "id": 52
      },
      {
        "trace": "rack (2.0.1) lib/rack/runtime.rb:22:in `call'",
        "id": 53
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'",
        "id": 54
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'",
        "id": 55
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'",
        "id": 56
      },
      {
        "trace": "rack (2.0.1) lib/rack/sendfile.rb:111:in `call'",
        "id": 57
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/engine.rb:522:in `call'",
        "id": 58
      },
      {
        "trace": "puma (3.6.0) lib/puma/configuration.rb:225:in `call'",
        "id": 59
      },
      {
        "trace": "puma (3.6.0) lib/puma/server.rb:578:in `handle_request'",
        "id": 60
      },
      {
        "trace": "puma (3.6.0) lib/puma/server.rb:415:in `process_client'",
        "id": 61
      },
      {
        "trace": "puma (3.6.0) lib/puma/server.rb:275:in `block in run'",
        "id": 62
      },
      {
        "trace": "puma (3.6.0) lib/puma/thread_pool.rb:116:in `call'",
        "id": 63
      },
      {
        "trace": "puma (3.6.0) lib/puma/thread_pool.rb:116:in `block in spawn_thread'",
        "id": 64
      }
    ],
    "Framework Trace": [
      {
        "trace": "bing_translator (4.5.0) lib/bing_translator.rb:179:in `rescue in result'",
        "id": 0
      },
      {
        "trace": "bing_translator (4.5.0) lib/bing_translator.rb:173:in `result'",
        "id": 1
      },
      {
        "trace": "bing_translator (4.5.0) lib/bing_translator.rb:45:in `translate'",
        "id": 2
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'",
        "id": 5
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/base.rb:188:in `process_action'",
        "id": 6
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'",
        "id": 7
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'",
        "id": 8
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'",
        "id": 9
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'",
        "id": 10
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'",
        "id": 11
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'",
        "id": 12
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'",
        "id": 13
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'",
        "id": 14
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `block in instrument'",
        "id": 15
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'",
        "id": 16
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `instrument'",
        "id": 17
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'",
        "id": 18
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'",
        "id": 19
      },
      {
        "trace": "activerecord (5.0.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'",
        "id": 20
      },
      {
        "trace": "actionpack (5.0.0.1) lib/abstract_controller/base.rb:126:in `process'",
        "id": 21
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal.rb:190:in `dispatch'",
        "id": 22
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_controller/metal.rb:262:in `dispatch'",
        "id": 23
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'",
        "id": 24
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'",
        "id": 25
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'",
        "id": 26
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `each'",
        "id": 27
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'",
        "id": 28
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'",
        "id": 29
      },
      {
        "trace": "warden (1.2.6) lib/warden/manager.rb:35:in `block in call'",
        "id": 30
      },
      {
        "trace": "warden (1.2.6) lib/warden/manager.rb:34:in `catch'",
        "id": 31
      },
      {
        "trace": "warden (1.2.6) lib/warden/manager.rb:34:in `call'",
        "id": 32
      },
      {
        "trace": "rack (2.0.1) lib/rack/etag.rb:25:in `call'",
        "id": 33
      },
      {
        "trace": "rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'",
        "id": 34
      },
      {
        "trace": "rack (2.0.1) lib/rack/head.rb:12:in `call'",
        "id": 35
      },
      {
        "trace": "activerecord (5.0.0.1) lib/active_record/migration.rb:552:in `call'",
        "id": 36
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'",
        "id": 37
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'",
        "id": 38
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'",
        "id": 39
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'",
        "id": 40
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'",
        "id": 41
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'",
        "id": 42
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'",
        "id": 43
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'",
        "id": 44
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'",
        "id": 45
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'",
        "id": 46
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'",
        "id": 47
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'",
        "id": 48
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'",
        "id": 49
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'",
        "id": 50
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'",
        "id": 51
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'",
        "id": 52
      },
      {
        "trace": "rack (2.0.1) lib/rack/runtime.rb:22:in `call'",
        "id": 53
      },
      {
        "trace": "activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'",
        "id": 54
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'",
        "id": 55
      },
      {
        "trace": "actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'",
        "id": 56
      },
      {
        "trace": "rack (2.0.1) lib/rack/sendfile.rb:111:in `call'",
        "id": 57
      },
      {
        "trace": "railties (5.0.0.1) lib/rails/engine.rb:522:in `call'",
        "id": 58
      },
      {
        "trace": "puma (3.6.0) lib/puma/configuration.rb:225:in `call'",
        "id": 59
      },
      {
        "trace": "puma (3.6.0) lib/puma/server.rb:578:in `handle_request'",
        "id": 60
      },
      {
        "trace": "puma (3.6.0) lib/puma/server.rb:415:in `process_client'",
        "id": 61
      },
      {
        "trace": "puma (3.6.0) lib/puma/server.rb:275:in `block in run'",
        "id": 62
      },
      {
        "trace": "puma (3.6.0) lib/puma/thread_pool.rb:116:in `call'",
        "id": 63
      },
      {
        "trace": "puma (3.6.0) lib/puma/thread_pool.rb:116:in `block in spawn_thread'",
        "id": 64
      }
    ],
    "Application Trace": [
      {
        "trace": "app/controllers/application_controller.rb:49:in `translate_text'",
        "id": 3
      },
      {
        "trace": "app/controllers/application_controller.rb:13:in `translate'",
        "id": 4
      }
    ]
  },
  "exception": "#<BingTranslator::Exception: undefined method `encoding' for nil:NilClass>",
  "error": "Internal Server Error",
  "status": 500
}
// POST http://localhost:3000/translate
// HTTP/1.1 500 Internal Server Error
// Content-Type: application/json; charset=utf-8
// X-Request-Id: a13e482b-3ead-459f-b97e-28450e6bc3f4
// X-Runtime: 1.142358
// Content-Length: 12257
// Request duration: 1.207324s

from bing_translator-gem.

pawandubey avatar pawandubey commented on August 16, 2024

Interestingly enough, when trying to use it from IRB, I first encountered some error related to rubyntlm. I installed that gem, and now bing_translator works fine from within the console but doesn't work with rails.

from bing_translator-gem.

pawandubey avatar pawandubey commented on August 16, 2024

Sorry about this. This was all me. 😅

from bing_translator-gem.

solson avatar solson commented on August 16, 2024

@pawandubey No worries. Glad you got it figured out. 😃

from bing_translator-gem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.