简体   繁体   English

推送到heroku后出现500错误-调试

[英]500 error after pushing to heroku - DEBUG

Im having an openuri issue when in production. 我在生产中遇到openuri问题。 The code below works in development but when in production the unauthorized error comes up. 以下代码在开发中可用,但在生产中会出现未经授权的错误。 The only way i've solved this is if i put the api key directly in the url, which obviously i dont want to do. 我解决此问题的唯一方法是,如果我将api键直接放在url中,显然我不想这样做。 Any ideas why my current code doesnt work? 任何想法为什么我当前的代码不起作用?

  api_key = ENV["NEWS_API"] url = "https://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=#{api_key}" article_serialized = open(url).read @articles = JSON.parse(article_serialized) 

 2018-10-25T01:55:47.184856+00:00 app[web.1]: F, [2018-10-25T01:55:47.184804 #4] FATAL -- : [40a7ee38-ef6e-4622-ad86-edb34d7eeccf] OpenURI::HTTPError (401 Unauthorized): 

 Running rails db:migrate on ⬢ twittter-clone... up, run.6483 (Free) D, [2018-10-25T01:12:44.387465 #4] DEBUG -- : (0.9ms) SELECT pg_try_advisory_lock(2661719123600558280) D, [2018-10-25T01:12:44.433095 #4] DEBUG -- : (2.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC D, [2018-10-25T01:12:44.456835 #4] DEBUG -- : ActiveRecord::InternalMetadata Load (3.8ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]] D, [2018-10-25T01:12:44.480937 #4] DEBUG -- : (5.3ms) BEGIN D, [2018-10-25T01:12:44.485057 #4] DEBUG -- : (1.7ms) COMMIT D, [2018-10-25T01:12:44.492822 #4] DEBUG -- : (7.1ms) SELECT pg_advisory_unlock(2661719123600558280) 

OpenURI returns a 401 error and my guess is that the ENV['NEWS_API'] is not set. OpenURI返回401错误,我的猜测是未设置ENV['NEWS_API'] You can run heroku config in the terminal or look it up on the web interface: Settings -> Reveal Config Vars 您可以在终端中运行heroku config或在Web界面上查找它: Settings > Reveal Config Vars

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM