Someone Please Help Fix My Python App

I think its a caching issue - if I test from a browser - it works but it's not updating in Snap!

image

image

Hmm, so how would we keep the url block from caching...

No idea :frowning:

I have an idea... Just let me test it...

Nope, didnt work...

@bh, how would we keep Snap! from caching the result from the url?

Another idea! We can pick a completely random number and put it in the url, and the sofware will just ignore it!

That bodge seems to work :slight_smile:

image

actually it is /set/123456/var/val

Everything but 'Delete' works in Snap!
Here is the project I am using: Snap! 6.9.2 Build Your Own Blocks
EDIT: I fixed it.
EDIT2: It is ready to share!
EDIT3: The server is up!

@cymplecy, how do I make it shows all the keys stored?
Current code:

@app.route('/all')
def all():
  keys = db.keys()
  return keys

Result (Console):

TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a set.

It isn't working

Allorigin CORS Proxy is not necessary just remove the second "app" reinitialization

app = Flask(__name__)
CORS(app)

#app = Flask(__name__)

Also instead of HTML you can just return value. So you can check if everything is stored OK.

@app.route('/set/<randomnum>/<name>/<val>')
def set(randomnum, name, val):
  db[name] = val
  return db[name]

This way cache-control header will be sent

@app.after_request
def add_header(response):
    response.cache_control.max_age = 0
    return response

List...

@app.route('/list')
def list():
  return str( db)

untitled script pic (90)

@app.route('/lst')
def lst():
  return ",".join( db.keys())

untitled script pic (92)

Why is this not working?

@app.route('/all/<code>')
def all(code):
 if code == os.environ['password']
  keys = db.keys()
  return ", ".join( db.keys())
 else
  return ('Invalid Code!')
@app.route('/all/<code>')
def all(code):
 if code == os.environ['password']:
  keys = db.keys()
  return ", ".join( db.keys())
 else:
  return ('Invalid Code!')

I've not seen any real problem so far, only syntax. So maybe you should look at Python Tutorial

You don't need to import flask twice. You can say from flask import Flask, render_templates,
aborts, requests
and you don't need a ping just for uptimerobot. You can set the uptimerobot URL to the normal site and set the ping type to HTTP.

Im doing that for a reason. (So I know if uptimerobot is pinging or a user is setting a var.)

Ah. And the flask part?

I'd rather not.

Why not? It's unnessacary code and can potentially slow down your script and confuse those who read it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.