How to retrieve BLOB from sqlite, Flask app? I get a "TypeError: read_blob() missing 1 required positional argument: 'podcast_id' error"

Viewed 30

Reading BLOB from database

def write_file(binary_data, filename):
    with open(filename, 'wb') as file:
         file.write(binary_data)

Below, def to put it in a dictionary, since I need it in a json format.

My table name is podcasts, contains: a primary key = podcast_id blob named = podcast foreign key = level_id foreign key = unit_id

def read_blob(podcast_id):

    try: 
        conn = connect_to_db()
       
        cur = conn.cursor()
        query = "SELECT * FROM podcasts WHERE id = ?"
        cur.execute(query, (podcast_id,))

        row = cur.fetchall()

        for i in row:
            print("podcast_id", i[0])
            podcast = i[1]
            print("level_id", i[2])
            print("unit_id", i[3])
            print("Storing podcast on disk \n")

            podcastPath = "E:\Python3\podcasts\db_data\\" + name + ".mp3"
            write_file(podcast,podcastPath)
        
        cur.close()
    
    except sqlite3.Error as error: 
        print(error)

    finally:
        if conn:
            conn.close()
            print("sqlite connection is closed")


read_blob(1)
       


@app.route('/api/levels/units/podcasts', methods=['GET'])
def api_get_podcasts():
    return read_blob()
0 Answers
Related