Ejemplo n.º 1
0
 def __init__(self):
     config = ConfigLoader()
     host = config.get_conf_str("mysql", "host")
     port = config.get_conf_int("mysql", "port")
     user = config.get_conf_str("mysql", "user")
     pwd = config.get_conf_str("mysql", "pwd")
     charset = str(config.get_conf_str("mysql", "charset"))
     # 异常处理
     try:
         self.mysql = pymysql.connect(
             host=host,
             user=user,
             password=pwd,
             database=None,
             port=port,
             cursorclass=pymysql.cursors.DictCursor,
             charset='utf8')  # 返回字典对象
     except Exception as e:
         print("Mysql connect failed!")
Ejemplo n.º 2
0
 def __init__(self, method, url, data=None, cookies=None, headers=None):
     config1 = ConfigLoader()
     url_pre = config1.get_conf_str("api", "url_pre")
     url = url_pre + url
     try:
         if method == "get":
             self.resp = requests.get(url=url,
                                      params=data,
                                      cookies=cookies,
                                      headers=headers)
         elif method == "pose":
             self.resp = requests.post(url=url,
                                       data=data,
                                       cookies=cookies,
                                       headers=headers)
         elif method == "delete":
             self.resp = requests.delete(url=url,
                                         data=data,
                                         cookies=cookies,
                                         headers=headers)
     except Exception as e:
         raise e