I have an app built with Flask & Plotly Dash - a bit of a mashup to enable subscriptions for a dashboard via PayPal.
I can't replicate the error in development, but I am sometimes getting an error in the Heroku logs when someone signs up, but can't get through the paypal subscription process. One person mentioned the paypal loading is in an endless loop, but otherwise not clear on the issue.
The error from the logs is this, but the link isn't helpful to me:
output_value = func(*args, **kwargs) # %% callback invoked %%
File "/app/index.py", line 347, in successful
conn.execute(upd)
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1263, in execute
return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1452, in _execute_clauseelement
ret = self._execute_context(
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1814, in _execute_context
self._handle_dbapi_exception(
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1995, in _handle_dbapi_exception
util.raise_(
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
raise exception
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1771, in _execute_context
self.dialect.do_execute(
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 717, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL SYSCALL error: EOF detected
[SQL: UPDATE users SET subscribed=%(subscribed)s WHERE users.id = %(id_1)s]
[parameters: {'subscribed': 0, 'id_1': '11'}]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
line 347 in successful from index.py refers to the following code. Line 347 is the conn.execute in the 3rd last else statement in the code.
@app.callback(
Output('url_login', 'pathname')
, [Input('login-button', 'n_clicks')]
, [State('uname-box', 'value')
, State('pwd-box', 'value')])
def successful(n_clicks, username, password):
conn = psycopg2.connect(
dbname=dbname,
user=dbuser,
password=dbpassword,
host=dbhost,
port=dbport,
sslmode=os.environ['sslmode']
)
c = conn.cursor()
if paypalenv == "Live":
environment = LiveEnvironment(client_id=client_id, client_secret=client_secret)
else:
environment = SandboxEnvironment(client_id=client_id, client_secret=client_secret)
client = PayPalHttpClient(environment)
user = Users.query.filter_by(username=username).first()
if user:
if check_password_hash(user.password, password):
login_user(user)
cuid = current_user.get_id()
c.execute(f"select orderid from users where id = {cuid}")
oid = c.fetchone()
c.execute(f"select status from users where id = {cuid}")
status = c.fetchone()
if oid[0] is not None:
act = SubscriptionActivate(oid[0])
try:
response = client.execute(act)
except:
response = None
if response is not None:
if response.result.status == 'ACTIVE':
upd = update(Users).where(Users.id == cuid).values(subscribed=1, status= 'ACTIVE')
conn = engine.connect()
conn.execute(upd)
conn.close()
else:
upd = update(Users).where(Users.id == cuid).values(subscribed=0)
conn = engine.connect()
conn.execute(upd)
conn.close()
return '/subscribe'
else:
upd = update(Users).where(Users.id == cuid).values(subscribed=0)
conn = engine.connect()
conn.execute(upd)
conn.close()
return '/subscribe'
else:
pass
else:
pass
Appreciate any help, can't find any answers on this and not sure how to test / replicate the issue!