m8chaa commited on
Commit
64d6404
·
verified ·
1 Parent(s): 5e36e2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -87,7 +87,7 @@ async def record_failure(s3_original_url, failed_task, sheetID):
87
  "message": failed_task,
88
  "sheetID": sheetID,
89
  }
90
- async with httpx.AsyncClient(follow_redirects=True) as client:
91
  response = await client.post(appsScriptsURL, json=body)
92
  if response.status_code != 200:
93
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
@@ -95,7 +95,7 @@ async def record_failure(s3_original_url, failed_task, sheetID):
95
 
96
  # post the processed image to google apps script
97
  async def post_to_google_apps_script(appsScriptsURL, body, s3_orginal_url):
98
- async with httpx.AsyncClient(follow_redirects=True, timeout=timeout) as client:
99
  response = await client.post(appsScriptsURL, json=body)
100
  if response.status_code != 200:
101
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
@@ -187,7 +187,7 @@ async def detect_receipts(image_contents, s3_orginal_url, sheetID):
187
  dezgo_headers = {
188
  'X-Dezgo-Key': dezgo_api_key,
189
  }
190
- async with httpx.AsyncClient(timeout=timeout) as client:
191
  response = await client.post('https://api.dezgo.com/remove-background', headers=dezgo_headers, files=files)
192
  # if successful, pass the masked image to cutting_image function
193
  if response.status_code == 200:
@@ -353,7 +353,7 @@ async def mobile_process_receipts(background_tasks: BackgroundTasks, request: Re
353
  "data": data,
354
  "mode": "alert-user"
355
  }
356
- async with httpx.AsyncClient(follow_redirects=True) as client:
357
  response = await client.post(appsScriptsURL, json=body)
358
  if response.status_code != 200:
359
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
@@ -396,7 +396,7 @@ async def sync_contacts(background_tasks: BackgroundTasks, sheeturl: str = Form(
396
  return {"message": "Contacts processing completed."}
397
 
398
  async def post_to_url(background_tasks: BackgroundTasks, url: str, json: dict):
399
- async with httpx.AsyncClient(follow_redirects=True) as client:
400
  response = await client.post(url, json=json)
401
  if response.status_code != 200:
402
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
@@ -467,7 +467,7 @@ async def detect_photo(background_tasks: BackgroundTasks, sheetID: str = Form(..
467
  "mode": "process-photo",
468
  "sheetID": sheetID,
469
  }
470
- async with httpx.AsyncClient(follow_redirects=True) as client:
471
  response = await client.post(appsScriptsURL, json=body)
472
  if response.status_code != 200:
473
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
 
87
  "message": failed_task,
88
  "sheetID": sheetID,
89
  }
90
+ async with httpx.AsyncClient(timeout=300.0, follow_redirects=True) as client:
91
  response = await client.post(appsScriptsURL, json=body)
92
  if response.status_code != 200:
93
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
 
95
 
96
  # post the processed image to google apps script
97
  async def post_to_google_apps_script(appsScriptsURL, body, s3_orginal_url):
98
+ async with httpx.AsyncClient(timeout=300.0, follow_redirects=True, timeout=timeout) as client:
99
  response = await client.post(appsScriptsURL, json=body)
100
  if response.status_code != 200:
101
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
 
187
  dezgo_headers = {
188
  'X-Dezgo-Key': dezgo_api_key,
189
  }
190
+ async with httpx.AsyncClient(timeout=300.0, timeout=timeout) as client:
191
  response = await client.post('https://api.dezgo.com/remove-background', headers=dezgo_headers, files=files)
192
  # if successful, pass the masked image to cutting_image function
193
  if response.status_code == 200:
 
353
  "data": data,
354
  "mode": "alert-user"
355
  }
356
+ async with httpx.AsyncClient(timeout=300.0, follow_redirects=True) as client:
357
  response = await client.post(appsScriptsURL, json=body)
358
  if response.status_code != 200:
359
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
 
396
  return {"message": "Contacts processing completed."}
397
 
398
  async def post_to_url(background_tasks: BackgroundTasks, url: str, json: dict):
399
+ async with httpx.AsyncClienttimeout=300.0, follow_redirects=True) as client:
400
  response = await client.post(url, json=json)
401
  if response.status_code != 200:
402
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
 
467
  "mode": "process-photo",
468
  "sheetID": sheetID,
469
  }
470
+ async with httpx.AsyncClient(timeout=300.0, follow_redirects=True) as client:
471
  response = await client.post(appsScriptsURL, json=body)
472
  if response.status_code != 200:
473
  logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")