Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-imgs error #26

Open
cynthia-you opened this issue Nov 8, 2022 · 0 comments
Open

Multi-imgs error #26

cynthia-you opened this issue Nov 8, 2022 · 0 comments

Comments

@cynthia-you
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant