Comments (5)
@pawandubey Please paste the full stacktrace and the code you were running so we can investigate.
from bing_translator-gem.
@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.
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.
Sorry about this. This was all me. 😅
from bing_translator-gem.
@pawandubey No worries. Glad you got it figured out. 😃
from bing_translator-gem.
Related Issues (20)
- Returning characters used/left per month HOT 1
- Translate Array and Detect Array is missing HOT 2
- Is there a quota imposed by MS? HOT 3
- \r \n are not preserved HOT 10
- balance method not available HOT 4
- getaddrinfo: Name or service not known HOT 2
- SSL Error while trying to use this gem HOT 1
- undefined method `headers' for HTTP:Module (BingTranslator::Exception) HOT 2
- bad URI(is not URI?) HOT 2
- raises a nil error when detecting white spaces
- How to test code using the bing_translator gem? HOT 1
- Are you releasing 5.0.0? HOT 1
- The received token is of incorrect token type. : ID=0261.V2_Soap.Translate.2BE299C8 HOT 1
- Detecting fails request
- Error with rubyntlm HOT 1
- Build is failing (missing key?) HOT 3
- Error with savon version greater than 2.11.0 HOT 1
- Abbreviations? HOT 1
- Migration to API V3 HOT 16
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 bing_translator-gem.