编辑:朋友告诉我这个问题的答案。这个脚本实际上是按预期工作的,但Heroku期望将其作为网站运行,而它不是Web服务。那就是问题所在!
解决方案:使用像Django这样的Web框架。 TA-DAA!
第一次使用Heroku ...脚本非常简单:获取一些JSON并显示它。
import requests
import json
r = requests.get('http://steamcommunity.com/market/search/render/?query=&start=0&count=10&appid=570')
response = r.json()
print("Content-type: application/json")
print()
print(json.JSONEncoder().encode(response))
我有Procfile,我相信它是默认的(最基本的):
web: python server.py --port=$PORT
还有requirements.txt文件:
requests==2.6.0
成功部署后,当我在浏览器中打开它时出现此错误:
应用程序错误
应用程序中发生错误,无法提供您的页面。请稍后再试。
如果您是应用程序所有者,请查看日志以获取详细信息。
错误日志(简化了JSON结果,因为它很大):
2015-03-23T14:45:21.574258 + 00:00 heroku [web.1]:启动流程 命令
p ython test.py
2015-03-23T14:45:24.006938 + 00:00 app [web.1]: 内容类型:application / json 2015-03-23T14:45:24.007104 + 00:00 app [web.1]:{" pagesize":10," total_count":196 15," success":true, "开始":0," results_html":" JSON正确显示"}2015-03-23T14:45:24.006952 + 00:00 app [web.1] :()
2015-03-23T14:45:24.697675 + 00:00 heroku [web.1]:流程已退出 状态0 2015-03-23T14:45:24.716774 + 00:00 heroku [web.1]:状态已更改 从开始到崩溃2015-03-23T14:45:47.384763 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = 402eaf01 -c1c0-4ce7-9164-20b2c8446cda fwd =" 76.65.214.143" dy no = connect = service = status = 503 bytes = 2015-03-23T14:45:48.711722 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = 533995dd-50a2-403a-ba31-8c436da8c825 fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:45:49.222004 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = c2ee68af -f295-4ca9-b035-3a97e88f105b fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:45:49.502723 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = ef98b883-0995-4713-b8b5-cdee908ba868 fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:45:50.164614 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = aabced87 -6c3b-4945-b97b-a7010a0f58dd fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:45:50.480625 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = 6c950374-d9cd-4c4a-8951-e51410cf4d7c fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:45:50.910714 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = c247d63e -bb9b-4a22-8906-9c5a5a44dda9 fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:45:51.221878 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = 30b11aab-e7b9-493a-850f-e6fe5534a818 fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:45:51.674624 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = a6584cc3 -e633-4f79-82b8-42077a242069 fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:45:51.960557 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = 80236a6d-9283-49dc-ac2d-e1814152dbe8 fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:48:45.637494 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = a3b95988 -65ee-4a89-a477-4b9259dca26f fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:48:45.948123 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = d95ea486-3615-4402-9725-fbfdc3eec9ab fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:48:46.451410 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = b553aa00 -1386-479c-9bf3-06c014a92074 fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:48:46.707337 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = 846c269b-4b92-4146-8c21-78a0ec9e8ee6 fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:48:47.269222 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = 82ece324 -fe04-42cb-835e-3a9214c36c4a fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:48:47.578761 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = 7d76b309-bbae-4dc1-97eb-d8312cce9a12 fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes = 2015-03-23T14:57:57.751643 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /" host = dry-forest-3041.herokuapp.com request_id = 1eb273ec -ffd7-42ba-9c95-e92e6957449f fwd =" 76.65.214.143" dyno = connect = service = status = 503 bytes = 2015-03-23T14:57:58.032275 + 00:00
heroku [router]:at = error code = H10 desc =" App cra shed"方法= GET 路径=" /favicon.ico" host = dry-forest-3041.herokuapp.com request_ id = 0061f766-4c8d-4b49-9f0e-d9174e16f5fa fwd =" 76.65.214.143" DYNO = connect = servi ce = status = 503 bytes =
答案 0 :(得分:0)
我使用过heroku但只是在部署Ruby on Rails应用程序时所以我在黑暗中刺伤但它可能与请求模块和heroku无法导入它有关。
你设置了这样的版本号(最新的2.6.0)吗?
requests==2.6.0
答案 1 :(得分:0)
尝试使用:
pip freeze > requirements.txt
表示需求文件。
答案 2 :(得分:0)
我在Heroku上运行了太多脚本,你必须包含的2个文件是
**requirements.txt**
requests==2.5.3
gunicorn==0.17.2
wsgiref==0.1.2
**Procfile**
web: gunicorn script_file_name:app --log-file=-
如果您需要更多帮助,欢迎您