I am on Linux platform with Cassandra database. I want to insert Images data into Cassandra database using Python Code from a remote server. Previously, I had written a python code that inserts Images' data into MySQL database from a remote server. Please see the code below for MySQL

#!/usr/bin/python

# -*- coding: utf-8 -*-

import MySQLdb as mdb

import psycopg2

import sys

import MySQLdb

def read_image(i):

filename="/home/faban/Downloads/Python/Python-Mysql/images/im"

filename=filename+str(i)+".jpg"

print(filename)

fin = open(filename)

img = fin.read()

return img

con = MySQLdb.connect("192.168.50.12","root","faban","experiments" )

with con:

print('connecting to database')

range_from=input('Enter range from:')

range_till=input('Enter range till:')

for i in range(range_from,range_till):

cur = con.cursor()

data = read_image(i)

cur.execute("INSERT INTO images VALUES(%s, %s)", (i,data, ))

cur.close()

con.commit()

con.close()

This code successfully inserts data into MySQL database which is located at .12 I want to modify the same code to insert data into Cassandra database which is also located at .12 Please help me out in this regard.

More Muhammad Karam Shehzad's questions See All
Similar questions and discussions