Sample Header Ad - 728x90

sqlite3.OperationalError: no such column: stock_name

-1 votes
1 answer
1012 views
#user_input.py from flask import Flask, request, jsonify import sqlite3 app = Flask(__name__) def process_user_input(data): # Retrieve user input from the data stock_name = data.get('stockName') # Create a new connection and cursor conn = sqlite3.connect('C:/SQLite/pythonstock/database.db') c = conn.cursor() c.execute("SELECT price FROM stocks WHERE lower(stockName) = ?", (stock_name.lower(),)) # Fetch the result row = c.fetchone() if row: price = row # Access the first column (price) # Perform further operations with the retrieved price else: # Handle the case when no row is found for the given stock_name price = None # or any appropriate default value or error handling # Close the cursor and connection c.close() conn.close() processed_input = price # Create a JSON-serializable response response = {'processed_input': processed_input} return response def process_user_input1(data): print("Process_user_input1 started") # Retrieve user input from the data stock_name = data.get('stockName') BRstage=data.get('BRstage') # Create a new connection and cursor conn = sqlite3.connect('C:/SQLite/pythonstock/database.db') c = conn.cursor() c.execute('update stocks set BRstage=BRstage where stockName=stock_name') conn.commit() conn.close() processed_input1='success' response = {'processed_input1': processed_input1} return response Traceback (most recent call last): File "C:\Python312\Lib\site-packages\flask\app.py", line 1455, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\flask\app.py", line 869, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\flask_cors\extension.py", line 176, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) ^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\flask\app.py", line 867, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\flask\app.py", line 852, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\Steven\stock.investing.decision.making\my-app\flask-app\main.py", line 25, in process_user_input_route1 result = process_user_input1(data) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\Steven\stock.investing.decision.making\my-app\flask-app\user_input.py", line 57, in process_user_input1 c.execute('UPDATE stocks SET BRstage = ? WHERE lower(stockName) = ?', (BRstage, stock_name.lower())) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such column: stock_name 127.0.0.1 - - [06/Nov/2023 22:11:41] "POST /process_user_input1 HTTP/1.1" 500 - File "c:\Users\Steven\stock.investing.decision.making\my-app\flask-app\user_input.py", line 57, in process_user_input1 c.execute('UPDATE stocks SET BRstage = ? WHERE lower(stockName) = ?', (BRstage, stock_name.lower())) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such column: stock_name 127.0.0.1 - - [06/Nov/2023 23:21:36] "POST /process_user_input1 HTTP/1.1" 500 -
Asked by Steven (107 rep)
Nov 6, 2023, 03:05 PM
Last activity: Nov 6, 2023, 03:24 PM