JSONDecodeError : Лишние данные: строка 1 столбец 5 (char4) при использовании API и JSON в Django

Когда я использую SVD Stability.api API, мне показывается ошибка, которая выглядит так в Django, API, которое я использовал, это https://platform.stability.ai/docs/api-reference#tag/Image-to-Video

enter image description here

это мой view.py

def img2vid(request):
    error = None
    video = None
    form = ImageForm()
    context = None
    if request.method == 'POST':

        form = ImageForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()

            realImage = request.FILES['Image']
            imageName = str(form.cleaned_data['Image'])

            # check the extension of the image and return an error if its happen
            ext = pathlib.Path(imageName).suffix.replace(".", "")
            if (ext != "png" and ext != "jpeg" and ext != "jpg"):
                error = "Invalid Extension . PNG & JPEG are allowed only"
                return render(request, "img2vid.html", {'form': form, 'error': error})

            imgloc = rf'media\images\\{imageName}'
            imgloc2 = imgloc.strip().replace(" ", "_")

            image = Image.open(imgloc2)
            imgSize = image.size
            w, h = image.size
            new_w, new_h = w, h
            greater = h
            if h < w:
                greater = w
                if 300 <= abs(w - h) <= 2000:
                    new_w, new_h = 1024, 576
            elif h > w:
                if 300 <= abs(w - h) <= 2000:
                    new_w, new_h = 576, 1024

            if 0 <= abs(w - h) <= 299:
                new_w, new_h = 768, 768

            new_image = image.resize((new_w, new_h))
            new_image.save(imgloc2)
            response = requests.post(
                f"https://api.stability.ai/v2beta/image-to-video",
                headers={
                    "authorization": f"Bearer apitoken"},
                files={"image": open(imgloc2, "rb")},
                data={
                    "seed": 0,
                    "cfg_scale": 1.8,
                    "motion_bucket_id": 127
                },
            )

            apiId = response.json().get('id')
            print(response.content)
            print(apiId)
            count = 0
            while True:
                response = requests.get(
                    f"https://api.stability.ai/v2beta/generation/image-to-video/result/{apiId}",
                    headers={
                        'Accept': "application/json",
                        'authorization': f"Bearer apitoken"
                    },
                )
                print(response)
                if response.status_code == 202:
                    print("Generation in-progress, try again in 10 seconds.")
                    count = count+1
                    print(count)
                    time.sleep(10)
                elif response.status_code == 200:
                    print("Generation complete!")
                    video = response.json()["video"]
                    break
                else:

                    raise Exception(str(response.json()))
    return render(request, "img2vid.html", {"video": video, "form": form})

это терминал, когда он печатает вышеуказанное
print(response.content)

print(apiId)

print(response)
enter image description here

Можете ли вы, пожалуйста, объяснить, в чем заключается ошибка и есть ли способ, которым я могу ее исправить? Спасибо.

Вернуться на верх