1

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

1 Answers1

0

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.

  • Thanks a lot. I made the exact changes that you suggested and the script runs each time I hit the Heroku URL. I know this because I can see the corresponding changes in xively. But now the browser throws up '505 Internal Server Error'. Why is that? Is there something wrong with the code? – user3482357 Apr 01 '14 at 14:33
  • That error indicates HTTP version not supported. Could be some version incompatibility with the Xively API response. It could also be that you are opening up a data stream in an HTTP request. What do you see in the logs? –  Apr 04 '14 at 16:15
  • this was the entry in the heroku log: heroku[router]: at=info method=GET path=/ host=... request_id=... fwd=... dyno=web.1 connect=1ms service=792ms status=500 bytes=454 >>But the problem was solved when I added a -->return "Hello" statement at the end of the function in my script... the script works fine now... – user3482357 Apr 13 '14 at 14:09