Question

I am completely new to both Python and Heroku... I am trying to communicate with xively.com using the python script included below.

This script seems to work fine locally-it performs its intended function when I execute 'foreman start'.

But when I deploy the app and try and open the URL provided by Heroku, the browser throws up:

404 Not Found The requested URL was not found on the server.

The corresponding entry in the Heroku log is:

heroku[router]: at=info method=GET path=/ host=...... request_id=...... fwd="....." dyno=web.1 connect=1ms service=13ms status=404 bytes=384

#script to GET and PUT data to xively.com
import os
from flask import Flask
import xively

app = Flask(__name__)

key = 'FEED_KEY'  
feedid = 'FEED_ID'  

print "Starting Xively tutorial script"

client = xively.XivelyAPIClient(key) 
feed = client.feeds.get(feedid)
datastream = feed.datastreams.get("datastream1")

lev = datastream.current_value

client1 = xively.Client(key)  
datastream = xively.Datastream(id="datastream2", current_value= lev)  
client1.put('/v2/feeds/'+feedid, data={'datastreams': [datastream]}) 

I think it might have something to do with the absence of a statement such as: @app.route('/') ...in the script. I have tried to fix it by including @app.route('/') in the script but then the script just doesn't work. Am I supposed to include the site URL in the statement?

I would really appreciate any help I could get...

Was it helpful?

Solution

It looks like the script you've included is communicating with the Xively API (getting the feed and sending some data). Do you want this script to run once you go to your heroku web application? The purpose of your script, is to send and receive data from Xively, but the purpose of using "flask" is to build a web application and deploy it on heroku. I'm guessing you want to run the script you have, once you hit your heroku URL. If that's the case, then you have to put the entirety of your script under a function that routes to the path "/".

@app.route('/')
def run_xively_script():
    put your code here.

heroku[router]: at=info method=GET path=/ host=...... request_id=...... fwd="....." dyno=web.1 connect=1ms service=13ms status=404 bytes=384

If you deconstruct this message, it is saying that someone (I presume you) tried to access the heroku web application at the path "/", and that path was not found. This is because you have no function that runs on the "/" path in your code above. Try putting your xively script in the "put your code here" above. That should trigger running your code once you hit that path and redeploy the code on heroku.

Also go here http://flask.pocoo.org/ for information on a basic flask hello world application. Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top