#!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys import hashlib import requests import json from multiprocessing import Pool try: from urllib.parse import urlencode except: from urllib import urlencode base_path = os.path.dirname(os.path.abspath(__file__)) session = requests.Session() # 获取openid def fetch(id): try: host = 'https://test.boye.com' path = "/v2/" body = {"id":str(uid)} url="{}{}".format(host,path) headers = { 'Content-Type': 'application/json', 'Content-length':str(len(body)) } response = session.post(url,json.dumps(body),headers=headers) if response.status_code == 200: data = json.loads(response.text) return data return {} except Exception as e: print(e) return {} if __name__ == "__main__": pool = Pool(processes=5) for id in range(1,101): pool.apply_async(fetch, args=(id,)) pool.close() pool.join()