Kester
Kester

Reputation: 61

Failure to run a very simple Python script on Heroku

EDIT: A friend has told me the answer to this problem. This script is in fact working as intended, but Heroku is expecting to run this as web site while it's not a web service. That's where the problem is at!

Solution: Use a web framework, like Django. Ta-daa!


First time using Heroku...The script is very simple: getting some JSON and displays it.

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))

I have the Procfile, which I belive is the default (the most basic):

web: python server.py --port=$PORT

And the requirements.txt file:

requests==2.6.0

After a success deployment, I get this error when I open it in the browser:

Application Error

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

Error log (simplified the JSON result because it's huge):

2015-03-23T14:45:21.574258+00:00 heroku[web.1]: Starting process with command p ython test.py 2015-03-23T14:45:24.006938+00:00 app[web.1]: Content-type: application/json 2015-03-23T14:45:24.007104+00:00 app[web.1]: {"pagesize": 10, "total_count": 196 15, "success": true, "start": 0, "results_html": "JSON correctly displays"}

2015-03-23T14:45:24.006952+00:00 app[web.1]: ()

2015-03-23T14:45:24.697675+00:00 heroku[web.1]: Process exited with status 0 2015-03-23T14:45:24.716774+00:00 heroku[web.1]: State changed from starting to c rashed 2015-03-23T14:45:47.384763+00:00

heroku[router]: at=error code=H10 desc="App cra shed" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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" method=GET path="/" 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" method=GET path="/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=

Upvotes: 0

Views: 1197

Answers (3)

Muhammad Taqi
Muhammad Taqi

Reputation: 5424

I have too many scripts running on Heroku, the 2 files you must include is

**requirements.txt**
requests==2.5.3
gunicorn==0.17.2
wsgiref==0.1.2

**Procfile** 
web: gunicorn script_file_name:app --log-file=-

if you need more help, you are welcome

Upvotes: 0

Joseph Seung Jae Dollar
Joseph Seung Jae Dollar

Reputation: 1076

Try using :

pip freeze > requirements.txt

for the requirements file.

Upvotes: 0

Daniel Oram
Daniel Oram

Reputation: 8411

I've worked with heroku but only in deploying Ruby on Rails apps so I'm a stab in the dark but it may be related to the requests module and heroku not being able to import it.

did you set a version number (latest 2.6.0) like this?

requests==2.6.0

Upvotes: 0

Related Questions