비전 api 400 에러

비전 api 인식 후 이미지 파일을 다시 저장하는 중인데
잘되다가 중간에 오류가 뜨는건 어떻게 해결해야 할까요ㅠㅠ
참고로 완전 초보입니다ㅜㅜ

api

API_URL = 'https://dapi.kakao.com/v2/vision/face/detect'
MYAPP_KEY = '****'


def detect_face(filename):
    headers = {'Authorization': 'KakaoAK {}'.format(MYAPP_KEY)}

    try:
        files = { 'image' : open(filename, 'rb')}
        resp = requests.post(API_URL, headers=headers, files=files)
        resp.raise_for_status()
        return resp.json()
 
    except Exception as e:
        print(str(e))
        sys.exit(0)


def feature(filename, detection_result):

    image = Image.open(filename)

    faces = detection_result['result']['faces'][0]
    facial_points = faces['facial_points']
    fig_w, fig_h = detection_result['result']['width'], detection_result['result']['height']

    fig,ax = plt.subplots(figsize=(10,10))

    target_obj = ['right_eyebrow', 'left_eyebrow', 'jaw', 'right_eye', 'left_eye', 'lip', 'nose']

    for each_obj in target_obj:
        for each in facial_points[each_obj]:
            rect_face = patches.Circle((each[0]*fig_w, each[1]*fig_h), linewidth=3)
            ax.add_patch(rect_face)

    fig_2 = plt.gcf() 
    fig_2.savefig(str(filename).replace('jpg','png').replace('train','kakao'))
    plt.close(fig_2)

이미지

path_dir = './파일경로'
files = os.listdir(path_dir)

empty_list = []

for fname in tqdm(files):
    img_dir = os.path.join(path_dir, fname)
    detection_result = detect_face(img_dir)

    if not detection_result['result']['faces']:
      empty_list.append(fname)

    else:
      feature_result = feature(img_dir, detection_result)

print(len(empty_list))

오류메세지

400 Client Error: Bad Request for url: https://dapi.kakao.com/v2/vision/face/detect
Traceback (most recent call last):
  File "<ipython-input-23-f44073cfae1c>", line 15, in detect_face
    resp.raise_for_status()
  File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://dapi.kakao.com/v2/vision/face/detect

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-27-8cfc5935493f>", line 8, in <module>
    detection_result = detect_face(img_dir)
  File "<ipython-input-23-f44073cfae1c>", line 20, in detect_face
    sys.exit(0)
SystemExit: 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/IPython/core/ultratb.py", line 1169, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "/usr/local/lib/python3.6/dist-packages/IPython/core/ultratb.py", line 316, in wrapped
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/IPython/core/ultratb.py", line 350, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/usr/lib/python3.6/inspect.py", line 1490, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
AttributeError: 'tuple' object has no attribute 'tb_frame