Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask Issues
#1
Hi guys, hoping someone fancies helping me out. I have written a central heating control script in python 2, and as I haven't really done much with python 3 yet and I have some new features I want to add, I have decided to re-write the script using python 3 and a bit better planning.

I started some today and thought I would get flask up and running within the script before going on to other parts, I have flask working to a degree using a link I can't post yet. I got it to return hello world in the first part, but then when moving over to templates I get server 500.

Then I always get this when i run the script
Output:
--- Logging error --- Traceback (most recent call last):   File "/usr/lib/python3.4/logging/__init__.py", line 978, in emit     msg = self.format(record)   File "/usr/lib/python3.4/logging/__init__.py", line 828, in format     return fmt.format(record)   File "/usr/lib/python3.4/logging/__init__.py", line 565, in format     record.message = record.getMessage()   File "/usr/lib/python3.4/logging/__init__.py", line 328, in getMessage     msg = msg % self.args TypeError: %d format: a number is required, not str Call stack:   File "run.py", line 37, in <module>     app.run('0.0.0.0', '8080')   File "/usr/lib/python3/dist-packages/flask/app.py", line 772, in run     run_simple(host, port, self, **options)   File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 699, in run_simple     and 'http' or 'https', display_hostname, port)   File "/usr/lib/python3/dist-packages/werkzeug/_internal.py", line 87, in _log     getattr(_logger, type)(message.rstrip(), *args, **kwargs) Message: ' * Running on %s://%s:%d/' Arguments: ('http', '0.0.0.0', '8080')
My folder structure

/
/run.py
/app
/app/templates
/app/templates/index.html
/app/__init__.py
/app/views.py

run.py
#v0.0.1
#!/bin/python3
import os, sys, subprocess, socket, sqlite3
import math, glob
import datetime, time
import RPi.GPIO as GPIO
from app import app

workingdir='/media/Backup/GitHub/Heating'
lib_path = os.path.abspath(os.path.join(workingdir, 'lib'))
sys.path.append(lib_path)

day_temp=19.999
night_temp=23.999
daytime=['00:00' '17:00']

detectIP=['192.168.0.25', '192.168.0.26']

onCommand="ssh [email protected] 'sudo gpio write 8 0'"
offCommand="ssh [email protected] 'sudo gpio write 8 1'"

templog='app/database/templog_'
datalog='app/database/datalog.db'
status='app/variables/status'
manual='app/variables/manual'
wintermode='app/variables/winter'
advance='app/variables/advance'

GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)

hostname=socket.gethostname()
now = datetime.datetime.now()
time_now=''
date=''

app.run('0.0.0.0', '8080')
app/views.py
#!flask/bin/python3
from app import app

@app.route('/')
@app.route('/index')
def home():
    return render_template("index.html")
@app.route('/advance', methods=['GET', 'POST'])
def advance():
    return redirect("/")
@app.route('/manual', methods=['GET', 'POST'])
def manual():
    return redirect("/")
@app.route('/winter', methods=['GET', 'POST'])
def winter():
    return redirect("/")
app/__init__.py
#!flask/bin/python3
from flask import Flask, render_template, request, redirect

app = Flask(__name__)
from app import views
Cheers Iain
Reply


Messages In This Thread
Flask Issues - by iainstott - Oct-27-2016, 06:02 PM
RE: Flask Issues - by micseydel - Oct-27-2016, 06:58 PM
RE: Flask Issues - by iainstott - Oct-27-2016, 07:13 PM
RE: Flask Issues - by micseydel - Oct-27-2016, 07:26 PM
RE: Flask Issues - by iainstott - Oct-27-2016, 07:50 PM
RE: Flask Issues - by iainstott - Oct-28-2016, 11:54 AM
RE: Flask Issues - by iainstott - Oct-28-2016, 02:05 PM
RE: Flask Issues - by snippsat - Oct-28-2016, 02:52 PM
RE: Flask Issues - by iainstott - Oct-28-2016, 04:01 PM
RE: Flask Issues - by snippsat - Oct-28-2016, 05:17 PM
RE: Flask Issues - by iainstott - Oct-29-2016, 02:38 PM
RE: Flask Issues - by snippsat - Oct-29-2016, 04:09 PM
RE: Flask Issues - by iainstott - Oct-29-2016, 06:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  flask issues with app structuring sidk23396 1 1,729 Feb-12-2020, 11:41 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020