Question

REST API Post is not working

  • 8 July 2021
  • 1 reply
  • 45 views

for filename in os.listdir(path):
    abs_file_path = os.path.abspath(filename)   
    if filename.endswith('.xliff'):
        with open(abs_file_path,'r') as f:
              
           try:
                headers = {
                    'X-Requested-With': 'XMLHttpRequest',
                    'Content-Type': 'application/json',
                    'X-APTRINSIC-API-KEY': '7dbf1a7d-a030-4656-9cac-e664016b208b',   
                }
                print(abs_file_path)
                response = requests.post(post_path,files={abs_file_path:f})
                response.raise_for_status()
                
                print(response.status_code)
                if response.status_code == 401:
                    files = {'file': open(abs_file_path, 'rb')}
                    response = requests.post(post_path,headers=headers, auth=HTTPBasicAuth(username,password),files=files)                                             
                if response.status_code != 200:
                    print("Upload NOT completed successfully!")      
       
           except requests.exceptions.HTTPError as errh:
                    print(errh)
           except requests.exceptions.ConnectionError as errc:
                    print(errc)
           except requests.exceptions.Timeout as errt:
                    print(errt)
           except requests.exceptions.RequestException as err:
                    print(err)


1 reply

Userlevel 7
Badge +1

@Janine Marlatt I have redirected this to our support team( ticket) for validation purpose.Thanks for sharing this here.

Reply