-1

I have read the xlsx sheet and used sha256().hexdigest() in this code, but getting errors:

for file in files_to_be_updated:
    print("file",source_path + '/' + file)
    file_bytes = pd.read_excel(source_path + '/' + file , index=False,encode="utf-8")
    source_hash = sha256(file_bytes).hexdigest()
    print(source_hash)

Error message:

Traceback (most recent call last):
  File "C:/Users/krishna/PycharmProjects/projcts/ispp-funds-platform-data-mart/test5.py", line 34, in <module>
    source_hash = sha256(file_bytes).hexdigest()
TypeError: object supporting the buffer API required
colidyre
  • 4,170
  • 12
  • 37
  • 53

1 Answers1

0

You are trying to feed a pandas dateframe into the sha256 constructor which expects a bytes like object.

Use hash_pandas_object from pandas.util instead if you want a hash for the dataframe, like this:

sha256(pd.util.hash_pandas_object(file_bytes).values).hexdigest()

See this answer

PnkFlffyUncrn
  • 123
  • 2
  • 6