【Python8】requests库,百度人脸API,IPCamera
发布日期:2021-04-30 21:06:37 浏览次数:96 分类:精选文章

本文共 3446 字,大约阅读时间需要 11 分钟。

requests?????????API??

1. requests?

??

requests??Python??????HTTP?????????Web API?????????????HTTP????????????????????

????

  • ??HTTP?HTTPS??
  • ??JSON?XML?????
  • ?????????
  • ?????????

????

  • ?????????????????????????????
  • API????????????????????????
  • ???????????????????API?????

????

  • ??????????????????API????
  • ????????????????????????????
  • ??????????????API??????????
  • ??????

    proxies = {
    'http': 'http://10.10.1.10:3128',
    'https': 'http://10.10.1.10:1080'
    }
    request_url = "https://api.example.com/v1/resource"
    response = requests.get(request_url, proxies=proxies)

    2. ????API

    ????

  • ??Access Token?

    • ?? ????API??
    • ???????API Key?Secret Key
    • ??????Access Token?
      import requests
      access_token = requests.post('https://aip.baidubce.com/oauth/2/token',
      json={
      'grant_type': 'client_credentials',
      'client_id': 'YOUR_API_KEY',
      'client_secret': 'YOUR_SECRET_KEY'
      }).json()['access_token']
  • API????

  • import requests
    import json
    url = "https://aip.baidubce.com/rest/2.0/face/v3/detect"
    image_path = "G:/your_image.jpg"
    with open(image_path, 'rb') as f:
    image_data = f.read()
    headers = {'Content-Type': 'application/json'}
    params = {
    'image': base64.b64encode(image_data).decode(),
    'image_type': 'BASE64',
    'face_field': 'age,gender,race,emotion'
    }
    response = requests.post(url, headers=headers, data=json.dumps(params), auth=(access_token, ''))
    content = response.json()
    if content['error_code'] == 0:
    results = content['result']['face_list']
    for face in results:
    print(face['gender']['type'])
    print(face['age'])
    # ?????race?emotion??????

    ????

    • ??????????JSON???????????
    • ???????error_code?error_msg????????
    • ???????????Excel??????????

    3. IPCamera?????

    ?????

    -- camera???
    CREATE TABLE camera (
    id INT AUTO_INCREMENT PRIMARY KEY,
    store_id INT,
    camera_code VARCHAR(100) NOT NULL,
    camera_ip VARCHAR(30) NOT NULL,
    camera_mac VARCHAR(150) NOT NULL,
    subnet_mask VARCHAR(30) NOT NULL,
    gateway VARCHAR(30) NOT NULL,
    day_exposure INT,
    night_exposure INT,
    resolution VARCHAR(30) NOT NULL,
    outofstock_search_status INT,
    binding_status INT,
    network_status INT,
    error_status INT,
    created_at DATETIME,
    updated_at DATETIME
    );
    -- store???
    CREATE TABLE store (
    id INT AUTO_INCREMENT PRIMARY KEY,
    customer_code VARCHAR(100) NOT NULL,
    store_code VARCHAR(100) NOT NULL,
    ssid VARCHAR(100) NOT NULL,
    password VARCHAR(100) NOT NULL,
    created_at DATETIME,
    update_at DATETIME
    );

    ????

  • ?????

    mysql -u root -p
  • ?????

    create database new_dbname;
  • ?????

    use new_dbname;
  • ????

    INSERT INTO camera (camera_code, camera_ip, camera_mac, subnet_mask, gateway, day_exposure, night_exposure, resolution) 
    VALUES('IPCAM001', '192.168.1.100', '001122334455667788', '255.255.255.0', '192.168.1.1', 1000, 2000, '1920x1080');
  • ??SQL??

    -- ??????
    ALTER TABLE camera CHANGE old_col new_col VARCHAR(200);
    -- ?????
    ALTER TABLE camera ADD COLUMN created_at DATETIME DEFAULT CURRENT_TIMESTAMP;
  • ????

    SELECT * FROM camera WHERE camera_code = 'IPCAM001';
  • ????

    DELETE FROM camera WHERE id = 1;
  • ????

    UPDATE camera SET camera_ip = '192.168.1.101' WHERE camera_code = 'IPCAM001';
  • ??????

    • ??SSID????
      http://IP/?custom=1&cmd=3029
    • ???????
      http://IP/?custom=1&cmd=2005&par=4
    • ???
      http://IP/?custom=1&cmd=1001

    ????????????IPCameras??????????????????????

    上一篇:File类的静态成员变量
    下一篇:Leetcode--209. 长度最小的子数组

    发表评论

    最新留言

    感谢大佬
    [***.8.128.20]2026年05月28日 13时48分19秒