I want to load data from PostgreSQL to Elasticsearch and I write below code, but it gives me the error in for loop, my code is as below:
from elasticsearch import Elasticsearch
#res = requests.get('http://localhost:9200')
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
sql_conn = psycopg2.connect(host="localhost",database="priyanka",user="postgres",password="admin")
sql_cursor = sql_conn.cursor()
sql=('SELECT * FROM "Sales"')
sql_cursor=sql_cursor.execute(sql)
tempList=[]
tmp = {}
for row in sql_cursor.fetchall():
print("1")
Sales_id =str(row[0])
Product_name =str(row[1])
sales =str(row[2])
tmp["Sales_id"]=Sales_id
tmp["name"]=Product_name
tmp["sales"]=sales
Error is:
Traceback (most recent call last):
File "D:/Priyanka Pagar/Softwares/Team/Python37/elastic - Copy.py", line 16, in <module>
for row in sql_cursor.fetchall():
AttributeError: 'NoneType' object has no attribute 'fetchall'
postgres
user from an application is poor practice. Your SELECT may have failed because you did not specify a schema.