client.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import requests, os
  2. def cls_process(path, client_id, one_key, name_column, api_key="sk-iREtaVNjamaBArOTlc_2BfGFJVPiU-9EjSFMUspIPBT3BlbkFJxS0SMmKZD9L9UumPczee4VKawCwVeGBQAr9MgsWGkA",
  3. proxy=False, chunk_size=100):
  4. # 定义请求的数据
  5. data = {
  6. "path": path,
  7. "client_id": client_id,
  8. "one_key": one_key,
  9. "name_column": name_column,
  10. "api_key": api_key,
  11. "proxy": proxy,
  12. "chunk_size":chunk_size
  13. }
  14. # 发送 POST 请求
  15. response = requests.post("http://10.41.3.69:8070/classify/", json=data)
  16. # 处理响应
  17. if response.status_code == 200:
  18. result = response.json()
  19. print("接口响应:", result)
  20. else:
  21. print(f"请求失败,状态码: {response.status_code}")
  22. print("错误信息:", response.text)
  23. def upload_process(file_path, client_id):
  24. # 表单数据
  25. data = {
  26. 'client_id': client_id
  27. }
  28. # 发送 POST 请求
  29. with open(file_path, 'rb') as file:
  30. name = os.path.basename(file_path)
  31. files = {
  32. 'file': (name, file, 'text/plain') # 'text/plain' 是文件类型,可以根据需要修改
  33. }
  34. response = requests.post("http://10.41.3.69:8070/uploadfile/", data=data, files=files)
  35. # 处理响应
  36. if response.status_code == 200:
  37. result = response.json()
  38. print("接口响应:", result)
  39. return result.get('file_path')
  40. else:
  41. print(f"请求失败,状态码: {response.status_code}")
  42. print("错误信息:", response.text)
  43. return None
  44. def both_process(path, client_id, one_key, name_column):
  45. file_path = upload_process(file_path=path, client_id=client_id)
  46. if file_path:
  47. cls_process(path=file_path, client_id=client_id, one_key=one_key, name_column=name_column)
  48. if __name__ == "__main__":
  49. both_process(path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin', one_key='网店单号', name_column='收货姓名')
  50. # upload_process(file_path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin')
  51. # cls_process(path="./process/wangdalin\\人群分类-自建站2024.08.xlsx",client_id='wangdalin', one_key='网店单号', name_column='收货姓名')