test_inference.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*-coding:utf8 -*-
  2. import requests
  3. import argparse
  4. def inference(ids, ip, port):
  5. url1 = f"http://{ip}:{port}/federation/1.0/inference"
  6. for id in ids:
  7. request_data_tmp = {
  8. "head": {
  9. "serviceId": "test_model_service",
  10. "applyId": "209090900991",
  11. },
  12. "body": {
  13. "featureData": {
  14. "phone_num": id,
  15. },
  16. "sendToRemoteFeatureData": {
  17. "device_type": "imei",
  18. "phone_num": id,
  19. "encrypt_type": "raw"
  20. }
  21. }
  22. }
  23. headers = {"Content-Type": "application/json"}
  24. response = requests.post(url1, json=request_data_tmp, headers=headers)
  25. print("url地址:", url1)
  26. print("请求信息:\n", request_data_tmp)
  27. print()
  28. print("响应信息:\n", response.text)
  29. print()
  30. if __name__ == '__main__':
  31. arg_parser = argparse.ArgumentParser()
  32. arg_parser.add_argument("--ids", type=str, nargs='+', help="Data identification", required=False,
  33. default=["123", "456"])
  34. arg_parser.add_argument("--ip", type=str, help="serving ip", required=False, default="127.0.0.1")
  35. arg_parser.add_argument("--port", type=str, help="serving port", required=False, default="8059")
  36. args = arg_parser.parse_args()
  37. ids = args.ids
  38. ip = args.ip
  39. port = args.port
  40. inference(ids=ids, ip=ip, port=port)