ValueError: embedded null byte

Hi so i am trying to insert images to my database though the shell, but keep on getting this error. Please help

import pandas as pd

from testing.models import retailer

from django.core.files import File

R = pd.read_json("Sample.json")

Title = R["title"].tolist()
Shop = R["shop"].tolist()
Country = R["country"].tolist()
Images = R["images"].tolist()

i = 1

for title,country,shop,images in zip(Title,Shop,Country,Images):

	A = images.replace("\\x","")

	binary_data = bytes.fromhex(A)

	K = retailer(title = title,country = country , shop = shop)'{i}-{title}.jpg', File(open(binary_data, 'rb')))


ValueError: embedded null byte


ValueError                                Traceback (most recent call last)
<ipython-input-8-34e8d0f9a4fb> in <module>
      3     binary_data = bytes.fromhex(A)
      4     K = retailer(title = title,country = country , shop = shop)
----> 5'{i}-{title}.jpg', File(open(binary_data, 'rb')))
      6     i+=1

ValueError: embedded null byte

In [9]:

Edited with Full error code

At that specific line of code, what is the data type of binary_data?

1 Like

i figured it out by using BytesIO