Skip to content

Multi-imgs error #26

@cynthia-you

Description

@cynthia-you

Add a func in removebg.py:

    def remove_background_and_save_img(self, img_file_path,save_path, size="regular", bg_color=None):
        """
        Removes the background given an image file and outputs the file as the original file name with "no_bg.png"
        appended to it.
        :param img_file_path: the path to the image file
        :param size: the size of the output image (regular = 0.25 MP, hd = 4 MP, 4k = up to 10 MP)
        """
        # Open image file to send information post request and send the post request
        img_file = open(img_file_path, 'rb')
        response = requests.post(
            API_ENDPOINT,
            files={'image_file': img_file},
            data={
                'size': size,
                'bg_color': bg_color
            },
            headers={'X-Api-Key': self.__api_key})
        response.raise_for_status()
        # print(f'input_file:{img_file.name}')
        st1=img_file.name.split('.')[0]
        st2=st1.split("/")[-1]
        # print(f'st2:{st2}')
        save_path=os.path.join(save_path,st2)
        print('save bg removed',save_path)
        self.__output_file__(response,  save_path + "_no_bg.png")

firstly, works well. After weekends,it report:" requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.remove.bg/v1.0/removebg "

Could u pls tell why

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions