使用Heroku来托管Sinatra应用程序。我有一条应该发送短信的路线。它会返回500内部服务器错误。
在localhost中,一切都运行得很好。日志显示Twilio :: REST :: RequestError。
main.rb的
post '/sms/send' do
@client = Twilio::REST::Client.new account_sid, auth_token
@client.account.messages.create(
from: '+xxxxxxxxxxx',
to: '+xxxxxxxxxxx',
body: 'Robot invasion! Reply back with any sightings.'
)
end
日志:
2017-05-17T19:04:24.640120+00:00 heroku[router]: at=info method=POST path="/sms/send" host=dysfunctionalapp.herokuapp.com request_id=a3736f1a-2264-4b91-b0a9-a3bde94342bd fwd="216.73.77.194" dyno=web.1 connect=0ms service=22ms status=500 bytes=255 protocol=https
2017-05-17T19:04:24.639060+00:00 app[web.1]: 2017-05-17 19:04:24 - Twilio::REST::RequestError - Twilio::REST::RequestError:
2017-05-17T19:04:24.639072+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/twilio-ruby-4.13.0/lib/twilio-ruby/rest/base_client.rb:125:in `connect_and_send'
2017-05-17T19:04:24.639074+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/twilio-ruby-4.13.0/lib/twilio-ruby/rest/base_client.rb:55:in `block (2 levels) in <class:BaseClient>'
2017-05-17T19:04:24.639075+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/twilio-ruby-4.13.0/lib/twilio-ruby/rest/list_resource.rb:94:in `create'
2017-05-17T19:04:24.639076+00:00 app[web.1]: /app/main.rb:84:in `block in <top (required)>'
2017-05-17T19:04:24.639078+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1632:in `call'
2017-05-17T19:04:24.639078+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1632:in `block in compile!'
2017-05-17T19:04:24.639079+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:991:in `block (3 levels) in route!'
2017-05-17T19:04:24.639095+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1010:in `route_eval'
2017-05-17T19:04:24.639096+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:991:in `block (2 levels) in route!'
2017-05-17T19:04:24.639097+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1037:in `block in process_route'
2017-05-17T19:04:24.639097+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1035:in `catch'
2017-05-17T19:04:24.639098+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1035:in `process_route'
2017-05-17T19:04:24.639099+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:989:in `block in route!'
2017-05-17T19:04:24.639099+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:988:in `each'
2017-05-17T19:04:24.639100+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:988:in `route!'
2017-05-17T19:04:24.639101+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1094:in `block in dispatch!'
2017-05-17T19:04:24.639101+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `block in invoke'
2017-05-17T19:04:24.639102+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `catch'
2017-05-17T19:04:24.639102+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `invoke'
2017-05-17T19:04:24.639103+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1091:in `dispatch!'
2017-05-17T19:04:24.639104+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:923:in `block in call!'
2017-05-17T19:04:24.639105+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `block in invoke'
2017-05-17T19:04:24.639105+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `catch'
2017-05-17T19:04:24.639106+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `invoke'
2017-05-17T19:04:24.639106+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:923:in `call!'
2017-05-17T19:04:24.639107+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:913:in `call'
2017-05-17T19:04:24.639108+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-protection-2.0.0/lib/rack/protection/xss_header.rb:18:in `call'
2017-05-17T19:04:24.639108+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-protection-2.0.0/lib/rack/protection/path_traversal.rb:16:in `call'
2017-05-17T19:04:24.639109+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-protection-2.0.0/lib/rack/protection/json_csrf.rb:26:in `call'
2017-05-17T19:04:24.639110+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-protection-2.0.0/lib/rack/protection/base.rb:50:in `call'
2017-05-17T19:04:24.639110+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-protection-2.0.0/lib/rack/protection/base.rb:50:in `call'
2017-05-17T19:04:24.639111+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-protection-2.0.0/lib/rack/protection/frame_options.rb:31:in `call'
2017-05-17T19:04:24.639112+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/logger.rb:15:in `call'
2017-05-17T19:04:24.639113+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/common_logger.rb:33:in `call'
2017-05-17T19:04:24.639113+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:231:in `call'
2017-05-17T19:04:24.639114+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:224:in `call'
2017-05-17T19:04:24.639114+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
2017-05-17T19:04:24.639115+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
2017-05-17T19:04:24.639116+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:194:in `call'
2017-05-17T19:04:24.639116+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1955:in `call'
2017-05-17T19:04:24.639117+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1499:in `block in call'
2017-05-17T19:04:24.639118+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1726:in `synchronize'
2017-05-17T19:04:24.639118+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1499:in `call'
2017-05-17T19:04:24.639125+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/connection.rb:86:in `block in pre_process'
2017-05-17T19:04:24.639125+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/connection.rb:84:in `catch'
2017-05-17T19:04:24.639126+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/connection.rb:84:in `pre_process'
2017-05-17T19:04:24.639127+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/connection.rb:53:in `process'
2017-05-17T19:04:24.639127+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/connection.rb:39:in `receive_data'
2017-05-17T19:04:24.639129+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/eventmachine-1.2.3/lib/eventmachine.rb:194:in `run_machine'
2017-05-17T19:04:24.639130+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/eventmachine-1.2.3/lib/eventmachine.rb:194:in `run'
2017-05-17T19:04:24.639130+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/backends/base.rb:73:in `start'
2017-05-17T19:04:24.639131+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/server.rb:162:in `start'
2017-05-17T19:04:24.639132+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/controllers/controller.rb:87:in `start'
2017-05-17T19:04:24.639133+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/runner.rb:200:in `run_command'
2017-05-17T19:04:24.639133+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/lib/thin/runner.rb:156:in `run!'
2017-05-17T19:04:24.639134+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/thin-1.7.0/bin/thin:6:in `<top (required)>'
2017-05-17T19:04:24.639135+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/bin/thin:22:in `load'
2017-05-17T19:04:24.639137+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load'
2017-05-17T19:04:24.639136+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/bin/thin:22:in `<top (required)>'
2017-05-17T19:04:24.639138+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load'
2017-05-17T19:04:24.639139+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in `exec'
2017-05-17T19:04:24.639140+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
2017-05-17T19:04:24.639138+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in `run'
2017-05-17T19:04:24.639140+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
2017-05-17T19:04:24.639141+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
2017-05-17T19:04:24.639142+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in `dispatch'
2017-05-17T19:04:24.639143+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
2017-05-17T19:04:24.639144+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in `start'
2017-05-17T19:04:24.639144+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/exe/bundle:34:in `block in <top (required)>'
2017-05-17T19:04:24.639145+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
2017-05-17T19:04:24.639146+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>'
2017-05-17T19:04:24.639146+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/bin/bundle:22:in `load'
2017-05-17T19:04:24.639147+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/bin/bundle:22:in `<main>'
2017-05-17T19:04:24.639551+00:00 app[web.1]: 216.73.77.194 - - [17/May/2017:19:04:24 +0000] "POST /sms/send HTTP/1.1" 500 30 0.0217
我有点迷茫。我为模糊而道歉。我应该从哪里开始?
答案 0 :(得分:0)
根据评论中的讨论,您有配置问题。您可以在本地(开发环境)而不是heroku(生产环境)中运行程序。
正如您在评论中提到的,您正在使用EVN来设置凭据。您可以通过两种方式设置此项以在Heroku中设置ENV。
1)在config/production.rb
2)推荐:从Heroku控制台设置ENV。这是Ref。链接执行Heroku config vars
您也可以将Figaro gem用于您的应用程序。
希望有所帮助!