Heroku - Unexpected Behaviour / Runs into errors at times, resubmitting pushes through / Sometimes Submits incorrect form data
I recently started experiencing this with my app.
Runs fine locally and seems fine after deployment.
But at times it behaves strangely. Like it's server side and not my app. Where it posts an error submitting a value.
But after clicking a few times it goes through. Server side.
It performed better while running on the Free Dyno. After upgrading it seems sluggish and unresponsive.
1 answer
-
answered 2021-02-23 01:10
ToddMcCullough
It appears as though I should be waiting a short while on some of my exceptions, because the Heroku Dyno may be somewhat slower than my local machine (my CPU is 9 years old though :/)
I've added sleep(1) and this appears to be solving the problem.
See also questions close to this topic
-
Print Variables in For Loop
from matplotlib.pyplot import figure T10,T11,T12,T13 = nx.random_tree(10),nx.random_tree(11),nx.random_tree(12),nx.random_tree(13) T = [T10,T11,T12,T13] for t in T: print("The Pruefer Code for -", pruefer_code(t)) fig = figure() axis = fig.add_subplot(111) nx.draw(t, **opts, ax = axis)
Which results in:
The Pruefer Code for - [2, 8, 1, 9, 5, 5, 6, 8] The Pruefer Code for - [9, 6, 10, 7, 4, 8, 10, 4, 6] The Pruefer Code for - [4, 1, 4, 8, 11, 11, 8, 3, 4, 8] The Pruefer Code for - [8, 7, 11, 4, 2, 7, 9, 1, 5, 10, 7]
Plus the graphs - how would I amend the code so it'd say:
The Pruefer Code for - T10 [2, 8, 1, 9, 5, 5, 6, 8] The Pruefer Code for - T11 [9, 6, 10, 7, 4, 8, 10, 4, 6] The Pruefer Code for - T12 [4, 1, 4, 8, 11, 11, 8, 3, 4, 8] The Pruefer Code for - T13 [8, 7, 11, 4, 2, 7, 9, 1, 5, 10, 7]
Any help appreciated :)
-
Get number of packets received by ping command in python
I need a function that can return the number of packets received or loss percentage. Before I used the code below to get true/false if I receive any of the packets. This should work in Windows, but if somebody can do it suitable for Linux too, I would be thankful.
def ping_ip(ip): current_os = platform.system().lower() parameter = "-c" if current_os == "windows": parameter = "-n" command = ['ping', parameter, '4', ip] res = subprocess.call(command) return res == 0
-
Tkinter GUI unresponsive
I'm pretty new to python and tkinter, so pardon me if I'm being naive. I'm trying to make a GUI for solving an engineering design problem using a widely accepted method (implying the method is seamless). The code for this method takes 0.537909984588623 seconds when run independently (not in tkinter but normal code), and its not too complex or tangled. When I tried to modify this code to fit into a GUI using tkinter, it becomes unresponsive after I enter all the inputs and select a button, even though the program keeps running in the background. Also, when I forcefully close the GUI window, the jupyter kernel becomes dead. Heres a brief outline of my code:
-----------------------------------------------code begins------------------------------------------
from tkinter import * from scipy.optimize import fsolve import matplotlib import numpy as np import threading from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.figure import Figure import matplotlib.pyplot as plt matplotlib.use('TkAgg') import math class MyWindow(): def __init__(self, win): self.lbl1=Label(win, text='Alpha') self.lbl2=Label(win, text='xd') self.lbl3=Label(win, text='xw') self.lbl4=Label(win, text='xf') self.lbl5=Label(win, text='q') self.lbl6=Label(win, text='Reflux Factor') self.lbl7=Label(win, text='Tray Efficiency') self.lbl8=Label(win, text='Total Number of Stages') self.lbl9=Label(win, text='Feed Stage') self.t1=Entry(bd=3) self.t2=Entry(bd=3) self.t3=Entry(bd=3) self.t4=Entry(bd=3) self.t5=Entry(bd=8) self.t6=Entry(bd=8) self.t7=Entry(bd=8) self.t8=Entry(bd=8) self.t9=Entry(bd=8) self.btn1=Button(win, text='Total Number of Stages ', command=self.stagesN) self.lbl1.place(x=100, y=80) self.t1.place(x=300, y=80) self.lbl2.place(x=100, y=130) self.t2.place(x=300, y=130) self.lbl3.place(x=100, y=180) self.t3.place(x=300, y=180) self.lbl4.place(x=100, y=230) self.t4.place(x=300, y=230) self.lbl5.place(x=100, y=280) self.t5.place(x=300, y=280) self.lbl6.place(x=100, y=330) self.t6.place(x=300, y=330) self.lbl7.place(x=100, y=380) self.t7.place(x=300, y=380) self.lbl8.place(x=800, y=130) self.t8.place(x=790, y=170) self.lbl9.place(x=800, y=210) self.t9.place(x=790, y=260) self.btn1.place(x= 500, y= 75) def originalEq(self,xa,relative_volatility): ya=(relative_volatility*xa)/(1+(relative_volatility-1)*xa) return ya def equilibriumReal(self,xa,relative_volatility,nm): ya=(relative_volatility*xa)/(1+(relative_volatility-1)*xa) ya=((ya-xa)*nm)+xa return ya def equilibriumReal2(self,ya,relative_volatility,nm): a=((relative_volatility*nm)-nm-relative_volatility+1) b=((ya*relative_volatility)-ya+nm-1-(relative_volatility*nm)) c=ya xa=(-b-np.sqrt((b**2)-(4*a*c)))/(2*a) return xa def stepping_ESOL(self,x1,y1,relative_volatility,R,xd,nm): x2=self.equilibriumReal2(y1,relative_volatility,nm) y2=(((R*x2)/(R+1))+(xd/(R+1))) return x1,x2,y1,y2 def stepping_SSOL(self,x1,y1,relative_volatility,\ ESOL_q_x,ESOL_q_y,xb,nm): x2=self.equilibriumReal2(y1,relative_volatility,nm) m=((xb-ESOL_q_y)/(xb-ESOL_q_x)) c=ESOL_q_y-(m*ESOL_q_x) y2=(m*x2)+c return x1,x2,y1,y2 def stagesN(self): relative_volatility=float(self.t1.get()) nm=float(self.t7.get()) xd=float(self.t2.get()) xb=float(self.t3.get()) xf=float(self.t4.get()) q=float(self.t5.get()) R_factor=float(self.t6.get()) xa=np.linspace(0,1,100) ya_og=self.originalEq(xa[:],relative_volatility) ya_eq=self.equilibriumReal(xa[:],relative_volatility,nm) x_line=xa[:] y_line=xa[:] al=relative_volatility a=((al*q)/(q-1))-al+(al*nm)-(q/(q-1))+1-nm b=(q/(q-1))-1+nm+((al*xf)/(1-q))-(xf/(1-q))-(al*nm) c=xf/(1-q) if q>1: q_eqX=(-b+np.sqrt((b**2)-(4*a*c)))/(2*a) else: q_eqX=(-b-np.sqrt((b**2)-(4*a*c)))/(2*a) q_eqy=self.equilibriumReal(q_eqX,relative_volatility,nm) theta_min=xd*(1-((xd-q_eqy)/(xd-q_eqX))) R_min=(xd/theta_min)-1 R=R_factor*R_min theta=(xd/(R+1)) ESOL_q_x=((theta-(xf/(1-q)))/((q/(q-1))-((xd-theta)/xd))) ESOL_q_y=(ESOL_q_x*((xd-theta)/xd))+theta x1,x2,y1,y2=self.stepping_ESOL(xd,xd,relative_volatility,R,xd,nm) step_count=1 while x2>ESOL_q_x: x1,x2,y1,y2=self.stepping_ESOL(x2,y2,relative_volatility,R,xd,nm) step_count+=1 feed_stage=step_count x1,x2,y1,y2=self.stepping_SSOL(x1,y1,relative_volatility\ ,ESOL_q_x,ESOL_q_y,xb,nm) step_count+=1 while x2>xb: x1,x2,y1,y2=self.stepping_SSOL(x2,y2,relative_volatility\ ,ESOL_q_x,ESOL_q_y,xb,nm) step_count+=1 xb_actual=x2 stagesN=step_count-1 self.t8.insert(END, str(stagesN)) return window=Tk() mywin=MyWindow(window) window.title('DColumn') window.geometry("1500x1500") window.mainloop()
-------------------------------------------Code end--------------------------------------------
I read on other articles that using multiple threads brings down the load on mainloop and prevents freezing. But like I said, the code isnt very complex. Is it still because of everythings running on the mainloop? Or is there something more than meets the eye? Is multithreading the only way to go past this point?
Thanks in advance.
-
Flask url_for in form action
I have a wtform in my html file, something like this:
{{ wtf.quick_form(form, action="/add/", method="post", extra_classes="form-horizontal", role="form", form_type="basic") }}
(I actually notice I can omit action). So this works.
Now - if I change it to
action="{{ url_for('add') }}"
, I'm ending up in this url:
http://127.0.0.1:5000/add/%7B%7B%20url_for('add')%20%7D%7D
If I just create a link in html like so:
<a href="{{ url_for('add') }}">link</a>
It does work and it gets me to /add/. I was wondering what the difference is. Thanks!
-
error while making many2many relationship in Flask
I need to make database in such way:
user –– id –– mail –– password –– orders (orders, relation)
dish –– id –– title –– price –– description –– picture –– category (relation)
categories –– id –– title –– dishes (meals, attitude)
orders –– id -- the date –– amount –– status -- post office -- telephone -- the address –– a list of dishes in the order ( many2many)
I use such code:
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) mail = db.Column(db.String) password = db.Column(db.String) orders = db.relationship("Order", back_populates='user') ####!!!!!!!!!!!!!!!!!!!!!!######### association_table = db.Table('association', db.Column('meal_id', db.Integer, db.ForeignKey('meals.id')), db.Column('order_id', db.Integer, db.ForeignKey('orders.id')) ) class Order(db.Model): __tablename__ = 'orders' id = db.Column(db.Integer, primary_key=True) data = db.Column(db.String) summ = db.Column(db.Float) status = db.Column(db.String) mail = db.Column(db.String) phone = db.Column(db.String) adresses = db.Column(db.String) user = db.relationship("User") user_id = db.Column(db.Integer, db.ForeignKey('users.id')) meals = db.relationship( "Meals", secondary=association_table, back_populates="meals" ) #### –– список блюд в заказе(можно через запятую, можно many2many) class Meals(db.Model): __tablename__ = 'meals' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String) description = db.Column(db.String) picture = db.Column(db.String) category = db.relationship("Category") category_id = db.Column(db.Integer, db.ForeignKey('category.id')) orders = db.relationship( "Order", secondary=association_table, back_populates="orders" ) class Category(db.Model): __tablename__ = 'categories' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String) meals = db.relationship("Meals", back_populates='category')
and I get an error:
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'meals.category_id' could not find table 'category' with which to generate a foreign key to target column 'id'
How should I solve this problem?
-
How to retrieve a row from SQLalchemy with flask
I am learning how to use SQLalchemy and databases in general with flask. I am following a tutorial and it uses the below classes and files.
https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database
To show an inserted row in the database, the tutorial uses the following:
from app.models import User >>> u = User(username='susan', email='susan@example.com') >>> u <User susan>
My problem is that I can not display the same output. I mean when I code the the statement, I get an error
from app.models import User
ImportError: No module named app.modelsPlease let me know how to adapt the posted code so I can retrieve data from database
** init **:
from flask import Flask from config import Config from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate app = Flask(__name__) app.config.from_object(Config) db = SQLAlchemy(app) migrate = Migrate(app, db) from app import routes, models
config:
import os basedir = os.path.abspath(os.path.dirname(__file__)) class Config(object): # ... SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'sqlite:///' + os.path.join(basedir, 'app.db') SQLALCHEMY_TRACK_MODIFICATIONS = False
models:
from app import db from app.models import User class User(db.Model): id = db.Column(db.Integer, primaty_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) def __repr__(self): return '<User {}>'.format(self.username)
-
Can't connect to Heroku postgres DB using Sequelize / NodeJS as missing sslmode tag
I'm playing with Heroku / DigitalOcean ("DO") App hosting services, trying to simply connect my NodeJS app to a Heroku/DO database. These services populate my environment variables with the following:
DATABASE_URL="postgresql://username:password@url:ip/dbname?sslmode=require"
Unfortunately, when I'm running Sequelize, I get the following error message:
ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "[my ip address]", user "[db user]", database "[db name]", SSL off
I think the connection string might be misconfigured as I can clearly see it's trying to connect over ssl.
$ node -v v15.9.0
-
My herkou discord.py bot is not starting and it is not getting any error
Hi I am hosting my bot on heroku. My first bot was online but when I changed code it stopped going online and I am getting no errors in the logs.
You can check my code at https://github.com/reyyan987/organic
Logs:
2021-02-27T13:29:06.299355+00:00 heroku[worker.1]: Starting process with command `python filename.py` 2021-02-27T13:29:07.003029+00:00 heroku[worker.1]: State changed from starting to up 2021-02-27T13:29:10.755961+00:00 heroku[worker.1]: Process exited with status 0 2021-02-27T13:29:10.819759+00:00 heroku[worker.1]: State changed from up to crashed
-
How to pass an access code from gmail api to a node worker in Heroku
The Application
I have written a discord bot with discord.js as a simple node.js application, not a webserver. I have integrated the gmail api with a credentials file to authenticate myself to access emails. This works perfectly in development on localhost.The Problem
When I start up the app, google prompts me to go to an external url and authorize the app. There I get a code and in the console of my application I am prompted to enter that code. It is fine when I run it on my machine, but when running on heroku, I just can't seem to pass the code back to the application.My (failed) Solutions
I have tried so far:- to use the heroku cli to pass the code back
- to use the integrated console (dynamo) in the heroku interface to pass the code back
- to blindly copy it in the logs when I was really desperate
In all attempts, the token was not saved in my deployed application, so the prompt came again and again.
The Code
The code in question to pass the code back is this:function getNewToken(oAuth2Client, callback) { const authUrl = oAuth2Client.generateAuthUrl({ access_type: "offline", scope: SCOPES, }); console.log("Authorize this app by visiting this url:", authUrl); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.question("Enter the code from that page here: ", code => { rl.close(); oAuth2Client.getToken(code, (err, token) => { if (err) { return console.error("Error retrieving access token", err); } oAuth2Client.setCredentials(token); // Store the token to disk for later program executions Fs.writeFile(TOKEN_PATH, JSON.stringify(token), err => { if (err) return console.error(err); console.log("Token stored to", TOKEN_PATH); }); callback(oAuth2Client); }); }); }
What can I do to solve this? Maybe just log the token via
console
and save it manually? Or is there another simpler way to authenticate that I do not see?