Ejemplo n.º 1
0
class HttpWebRequest(object):
    Url = ""
    # http://api.game.prod.32solo.com/inno72/service/open
    payload = ""
    # {\"serviceName\":\"createQrCode\",\"params\":{\"machineId\":\"18237422\"},\"version\":\"1.0.0\"}
    headers = {
        'Cache-Control': "no-cache",
        'Content-Type': "application/json",
        # 'Postman-Token': "6d05cd7d-1e3b-4292-b4ae-1e282f39f943"
    }

    def __init__(self):
        pass

    #post方法
    @property
    @retry(reNum=getYamlfield(gl.configFile)['RETRY']['ReNum'])
    def post(self):
        self.Url = self.Url
        #发送post请求
        res = requests.request("POST",
                               self.Url,
                               data=self.payload,
                               headers=self.headers)
        if res.status_code == 200:
            return res.json()
            # print a['data']['sessionUuid']
        else:
            return {"errcode": 9001, "errmsg": str(res)}
Ejemplo n.º 2
0
class HttpWebRequestget(object):
    Url = "http://api.game.36solo.com/api/getSamplingNew"
    # http://api.game.prod.32solo.com/inno72/service/open
    payload = '------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"machineCode\"\r\n\r\n18383061\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--'
    # print type(payload)
    # {\"serviceName\":\"createQrCode\",\"params\":{\"machineId\":\"18237422\"},\"version\":\"1.0.0\"}
    headers = {
        'content-type':
        "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
        'Cache-Control': "no-cache",
        'Content-Type': "application/form-data",
        # 'Postman-Token': "6d05cd7d-1e3b-4292-b4ae-1e282f39f943"
    }

    def __init__(self):
        pass

    #post方法
    @property
    @retry(reNum=getYamlfield(gl.configFile)['RETRY']['ReNum'])
    def post(self):
        self.Url = self.Url
        #发送post请求
        res = requests.request("POST",
                               self.Url,
                               data=self.payload,
                               headers=self.headers)
        if res.status_code == 200:
            return res.json()
            # print a['data']['sessionUuid']
        else:
            return {"errcode": 9001, "errmsg": str(res)}
Ejemplo n.º 3
0
 def __init__(self):
     self.curDateTime = str(
         time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))  #当前日期时间
     self.config = scripts.getYamlfield(
         os.path.join(gl.configPath, 'config.yaml'))  #配置文件路径
     self.sender = self.config['EMAIL']['Smtp_Sender']  # 从配置文件获取,发件人
     self.receivers = self.config['EMAIL']['Receivers']  # 从配置文件获取,接收人
     self.msg_title = self.config['EMAIL']['Msg_Title']  #从配置文件获取,邮件标题
     self.sender_server = self.config['EMAIL'][
         'Smtp_Server']  #从配置文件获取,发送服务器
     self.From = self.config['EMAIL']['From']
     self.To = self.config['EMAIL']['To']
Ejemplo n.º 4
0
class HttpWebRequests(object):
    Url = "/machine/initMachine"

    payload = 'cbd4e2944dc123025332f295e55c5685bac3b5fd079ddd392b6cc9197c2bdd881409e165e98fe599764f912c545ebf9b83929c942ac4821e9a32b41cb7c482ffbd7d9e07eda973f82862038aa5622e13f5930b36f499a7a00838cf47c788e0719831f558c552db80561b06d5d46c4571c17ef886e21f536d635a869b538ee5a677e61f15e19d16bf089c948d5e7bc0613143fac413ebeca208587df29077b00281721cc600c1e2e13e4a036a29c00f6ddcbca65e72a247233750ed366da69bdb1b4253a6a778a0416b9a4ae38fc96e073c71df4ab8e271014cf11a4b8a17d4af71cea0a9e7b0b56bf95a3fe013b35c73311f90e6bd99c9ce7e5de6c31649c7507840bec5a7589301bfd228ce8423816c3d84dd4d4dfca6b28b384627777d684c052d0004bab77356e9905b51b329bc28d71a6f16520fc3c86fec5a673f4da6c719c15bc5c1702a027d40389903b2c6131ad39fac62fc51f57ef4906d04c223d9c0a0ae82b62e98bfd27162a197212f77b851bbf05366b0ba09b9e690010003a01b2088b7992add46343bc7dcfcc555cdb545383e66dcb7f87b58ff67bb03229b88b0b06a4af726e7db7f946600322e2a6598017f90dd601337699013d6bd6e7dae0e89f136e84642edf4db8e9d405fec1ae236418b0130fe6b551ab51ddbdd6ebb745823c9591acfe2beee2c5e5072faa19b14e7183af2c7083636bc69d9c12911319a9171b5445282090e30dfd0107bb0c74e42af69b85c81aca154283f14e83a592960a7f1c44846cb4c937a63bd58ce8965a5c3de1c7fda432e2c29f06cd709f7db473ade35ef0ca5c5fbe143e75c180dbbc1b966dfcad22ac334f94b00fef549a7c3bda3cdc7c1af8729b3c1b8eedbadca098956c03c3f4e7a04488e096ff5f5ec9c0f3453c3a76c0eaf197d422ee011464be4e913895133c3ec8d35b7ae41d5f9d8cfbb4dee3ae66b9c02863a6b1ef0d8709bde6e4e3d9580a708e1f29b6b255e5ee7e8fc0ee568486dcea2f1bbf307fa547bd8b753bb7dbcac2e821de2728fb303ebe4aa34910821083b43c944c4e4af4b51fd797c6d3c73ee49577dfbca17b96977e7c939daee0f4806e5abbd9f63358dbaa7c040d50edeb95472de39198277a67d124427ee2b3b8be394387ce8316832960e3a7b69bcd2645d1e3d7d465ffdd4efa5411e0bb4fadd76e9a2eb9f7b2e192a6d588dad16dfef5d431d862350e16ccf1718549d3131fd35383acdb6c89c9e2fd93bc234329e4ec0b07a659cc053823df69a4271745acc9b44e329ba6c3bb99f3e5321862707731edea4d5e49d0c9aacfcf575b0361adbf7b3af40b914bc7fc626098dd35a1cb8fcf7caccf2028ded6243a0df009d184a4358c7fd437b8b39108fbc396fab83138316baa11f35e1e407cde910c122b500d11578783d068fb060c37fa7b5b2249f39e70ff34f7a4eddee1ae00b6f45dcd30ae53b9bb094d8fb1d7882594dac2eddfc40de578c81ea886fb5e598f6caf31e931af8e6122955108acb1814b73a859929fc8f22eb01c2f09cbfbb6356bbc36618ef4f2f2dd612c9706430e899e744268e455d9fa745813a40a17bc521b8c3f96ba1a2c82bf329f75e04c9a68c6b37ba61e40adc4c3a5494ce954c3a54497bc9e4f70f5c81b0821adc84568adebb51f8113daf0a7578a871fa86eb04c78699974bc6d0092cef8b7ae3421f1dd11ecf589cb6e86ab4796a8d5809f824f3266eeb3ce16ce51c4c182acc1665a1197d7ae8d532e178aa5882024aea79f7158a1fcfc50e09a1bbc4ab72fb03e59d970d8ef511bbf5826c676f8c0d815b7a639621e8f74fcacb3ed14adfc8ae171fab8ae3c8b6fb4bb47b88b9b5c04763b637dbacac963a485bfb1de9f1f2b530fe09a01a8de5c29a6e3143b8c3c03ede63ffc079eb59ffe6ff4ef1dfcc04a90a6061e27c54daa1bda7270d77598dca4d950c78bfed824eb39d24b6e5130b84a49c5325e52c6edde96c3b49ca66799ce1ac1e123e3c3b69d47c88b82e261e6a29ac9a8f04f1941638f73204199cf92cd43236f0d4b188d6ce4cc146911d6c9d66f2b45977d40bf6dafde63142dc4195aed6ff211e9b3325afabc958c98ed38ef3aa0dc8ad2a062b31fc74dd3bb0d7993bc3b5c73b83e4b0312de911cc9148e4afea659cdb5b5407f3f1adcc9b1a48b45fd01bdadad3af92020fcda2efb0786f3c5bb12843429fb9f60383a91487292ef1761a090efe21ee8ae19f0f3ad784d4408a39c18a7b2065633fcbab793209ceb83560d571f4160c7d6aa13b1717e9f6f3fbe75b60782f9da84e2e2e6853d147fb35c7c5c671d8c9b0ad3c0c0f06a835c6cc06cdad94d98f9bfe4e5032f832aa728c13c916dc03a059aa5c07a2d85a47dc01e0d4f30bb8c2f812a00948aac66e70e6480a06f57239454eb7c07801a3d4e6ec97b61d0c9457ac06353a0e0dd8866ccaba80652e6534f57fe6d79467e45d86b432d1d3bebc143d53dc10ab83bda6feab35ccb2dab6b899660a2d38993d314796e0b26caa3061bc577d2afc0f240d5aca95462b34fe74096dba4cdab66ca6f7dfbc0baed05af5b1a9cf22a571247c36e0f4415c4f4cce1d5271ff2bce563ffff5f88cff247706ded965c8347d9d3185087f6c2a560cb80bf1a7ae867306f1a0e7b1e0fe795f4738d981ba61c6c27972c8105d857b46eaea22a1cb75fa7c0d124976c39ca61532e95e4055f15e215811c830558cdaa62b37fcd94c5d9c674bf1b1163b9c68c0bafdb5167ec1c66576e404909cd4d2ee0a6d5795656ba35ec3273937b2b285098baac6aaeed409b291482f38efc81e639fb83e5a97bf4b410a9eec1fed521d2ee930cfe50d94acb36bf9aaee3d221bc35860de4c8247731fadac042eb58f1ea31cedb5eaa7c276a96076640512632ac31a4576a9b0519f9e666f8fdcad7547aaa332c194176d4ef3e0f60b36a2e6a2d98bc98aa478f462ec5ef33534bce044baddeb15960d3c2ef0efb538215f13caafb2d5091824046231bf69acbc0a356c749caa04dedb0300d7f89bfe95ae36ed3eda6ba66cf8f936079ab84bb78bcf35286981fd6bcacd725e06211ad54c5115645c542d5270ee1545c79352d53a4ad918e2de7508b49d80dc1f034376e1dc4859391235e5b597e4bdb34cf70984f148a625b4b458e75f5b3c38d8da5ac3259ef573dbd5fe06b8e4d2f7deced3fb25d32056dd220d1cac3896d2760df090bfed60a7974bee669206b7eab9a6a635a7ca11db8dfd8b8174c4372c8bab06f1f1195e2d89247871cd03adc9e27f85f1384b24a2747619744c8bc048b19b7569a7f8105329de27505f489e991d6a156fc69eb3eb5fa2c59e1d0dde921b49a708097a606118ab5e1bce790586d968a8a80b92fc4f4292962e139c336f23581ce4a14ed015148fdcee84cb4fefcf1c054a959ad7971f5a7c68a65486f271aad5fb1286fa4c5a89d3685fdeb5b81a3351e19b3b2d114c896cbc72d7df2d2b4500f061866297d422d5ebd87e28de7f0e659c6c643f862cf03b80feb09e777d775e84dd62f352ac8d1c910d80d910153daa9bde84ac1eaab1a5dfc0d81007cdf84e0843ff14ec9d4aa8cf602e84965f4c5eda2a864461468d4dfd859682645d34d2b98ad67a530072d304a331527e6dba44ff5c9084e06c275ecef8ef79d1aa88e0853ab3cce8e0de'

    #'keword=&code=&pageNo='
    # headers = {
    #     'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    #     'cache-control': "no-cache",
    #     'postman-token': "6eb8950f-4839-3857-15e9-91a14c7e1663"
    # }

    def __init__(self):
        pass

    def tokens(self):
        self.token = BaseConfig().base_token
        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
        }
        headers['lf-None-Matoh'] = self.token
        return headers

    #post方法
    @property
    @retry(reNum=getYamlfield(gl.configFile)['RETRY']['ReNum'])
    def post(self):
        #url拼接
        self.full_url = BaseConfig().base_url + self.Url

        #发送post请求
        res = requests.request("POST",
                               self.full_url,
                               data=self.payload,
                               headers=self.tokens())
        if res.status_code == 200:
            return res.json()
        else:
            return {"errcode": 9001, "errmsg": str(res)}
Ejemplo n.º 5
0
class HttpWebRequest(object):
    Url = "/machine/locale/detail"

    payload = {'id': '2ee7fd62a87d4887acb5f17e0c69bc79'}

    #'keword=&code=&pageNo='
    # headers = {
    #     'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    #     'cache-control': "no-cache",
    #     'postman-token': "6eb8950f-4839-3857-15e9-91a14c7e1663"
    # }

    def __init__(self):
        pass

    def token(self):
        self.token = BaseConfig().base_token
        headers = {
            'Content-Type': "application/x-www-form-urlencoded",
            'cache-control': "no-cache",
        }
        headers['lf-None-Matoh'] = self.token
        return headers

    #post方法
    @property
    @retry(reNum=getYamlfield(gl.configFile)['RETRY']['ReNum'])
    def post(self):
        #url拼接
        self.full_url = BaseConfig().base_url + self.Url

        #发送post请求
        res = requests.request("POST",
                               self.full_url,
                               data=self.payload,
                               headers=self.token())
        if res.status_code == 200:
            return res.json()
        else:
            return {"errcode": 9001, "errmsg": str(res)}
Ejemplo n.º 6
0
class HttpWebRequestss(object):
    Url = "/machine/initMachine"

    payload = '374ca4d9c398a8b3362166776744eea8c23e8af2c32f3a594e29b58e195d16f81f42820592288be7dd8580962bc60d0c711d531f60f910a64817bf5eaa0b60423c6c969e4f9964b69807eb3fa5b3aba8f112fb79c176f7097f0fd60f97e75dce874adcaa5d1d9677db5d1acdc3cc365ace4949bb09475807591a65ef0c721ee823446278c3f9dbf3b57512bef7f426e2edbac084c38d9bbf767641ebb3c7d3bf2d3cc7c6fca0fb44acba0e852b541cf4cac953ee0341ea5b9c466a604e9fff621217a41225e7ac641d95eeb818e2e41eeaea5952b7a76a1d7ac8e67f1f19db7839a84c88c4960647bc1a88995e795a86b2da4b10638bf942a462fa0b923f5c72fd6d945d5be42a2732135465ab17186cbf13dd53755c3d09291116ba8fd73f21be6b88a3a49c31aa9e32a70e9c071000e0df2a2823111701608b2a6cb7f0c4b0127db5bc57f1f5f064c12d83bf40776d8b06e5146c65b04fe59e95d874786f1097d69d9db0b6eb3db37d1926e9b9f0d80a7c822661b0db264796c516ea01305ac7959650ab195e807221a7008a2cf51688d8a408e61d1043828b798c84610bad2d877ddd8a4a79872e56cbdd2f6b12ed43229a25ba3f6b667aa248ccbb2bac436e0b937c0036c845124522b80e0c989bb64353d9cddc982553acc233c5c001d425981aafea7762ede583c9b33420e110ba4829539d0029bfd6be58bb5f755194b0a6f88ee4c488fc253038768b793fed771c441d83b3059a0a0774300cd2b3f76e1f2c8ba31d05985cec00abbe65a44813f5a17252364257b763c7fabdcf382a4d4580bf2b0c72e3688c3ae0ec76d52de08024c1fb0f9a9424292d2d08c5acb8c6a9396e355e779bffd0f6d3fd602bfe005a110a0fc6d3fdd050fe64244c38e3ad99037cfb165f63ce4bdeb77040cda06bdf273ea4a179b62b377e44b6c676142240b4046f60bc89ff1b18893af4951bf1d66298d9c94f5dbe6ac8db53755c7f0e7acaecd625357c0ecf54c0fc235365b5e80b3980fdb00d02c55f5000dd27d1147fb56b056287fbd9179c431a3bf98e0f057a59639386570636afa7bdd256609af1f049f2c49234f3922c016fddbfd14b1fc1c9859e6af3b0af661b16e89878b46879873521efc1fb8bca680e18e05757c0adbd4428943c0b6944b2d6c6c96df62bbce6a4995e0d1d904a8ef37f26fd27461973f2be9aec9e5c1241aebf0c561c75f341f27a80bc5264c5cac33fdc14b81b2fd5bc52be4bd7ab8ea63d81f94c45783f75b223dafe093d705326ec058dfeda8f502dadb4489aacc92c12aa80d476fcad95e52b0870925fd970e8310224c6590a1662a0359dc1ed4e58acae55dcd47ef833e05068ad9be066f14de566e3a641fea59fb8022160d6619f7a7142d624c72013bf3a35c4e71c19be8d743737293c60afc0be4c4210091745289f601941b496e6f26e9b46d48b7b1d3e86e177a2a3e6eaac9aaa86797fde008f1cca1edd43aaba565418be38ef5ed9eed169faa6fb99dec638e86e006a9cab5d0974e934188d97aa20633cf8b1f2a9450b5c0875fd8500c9acadfa1f453ad1425a324a1e5c29fdebd821f80e2e63dff804868d7abccc0256dd54faa759cb8f58f77c8239766752379d89cc319c8e58d30df7e7d1f614c7797fceec8419260d65ff90ce5dcdc62d7aa31d7d66b5bfb12bafcb6c43e09cfae7ccb17ad2c1482d50e87bbf4329116230b92de7ae2063b70c7499905e5d68df7b84383687e0527962e176c3bfee699ff5184c3dbb0fba5c28c4419db448375d7f5c459eed75361d114398d4b84133bfdb53e39f7217efd6ffa9442b47ba8a58cbe7e944a708e40d29c41d0f1998d572fbd1703e1ccbb511cfbdf48c40a40cbb66ea56ed27d2195b6a9f50de2996d4e0a4059faa4f31ec506c0b56a03b06d36e643febaf75ad2c88f92ddef301719579e22e7084f85c704299008d280593ca25ea1ef5144f10e08b45b22ddd3518e314a673b3e545e529d512e34b99b26fd7f327499d3bdb9be3c353227c035caa197d6eb9e129118c1e808253dc873c343b99854c117ee76fbaa8e5198ab41431fd60a3eacdec6b09999bc724050277447ce7844cba639962d8dcd2ac6e49deda2b5a53a46a463ee528cfbbb67d02a2a244acaa5036957af11a4b31dd8d740f0a43c7be85a09ec8b5379a327946cc9506ab9ce3a25ea1edb639f54eb87883b7877c71b2e2a5b2bf8ee9020dbeb24b23fb6a1db2b3f52ab1d39696ae7514f2874d3f78ad0983ec08028db804933b21c478ff6acd82c215d2f5e5ac071bbacf795ff600664991fb68613ba00310025f5cb6ba29a40b90141d9d1eef3ca20a0c12dc7d77ec5d4812f6d75675684cd8c62c43db0021440361b2298ae24168a43f8c4dcceb625fff27b491e42effa38ae2e655754793ce897961626913a058ba303c032e8a47c7dbb50f1af7d1e1278307315ae0dd6239f227b8b724f135ef04783a0fabf6d7a280e3f6703e98675112c4e53f7b96fb9132c5ee0a5edd7665b1c9aea886f2cc338c4776042f6ae74f4adabbc391c4eef7dc6b6e1e3f837633d1fd3d5d962bd04766f74b5f026e1461b926581e817878d4251c3cc2582927e2d1f41ae2b5b624e841dc88800061295b2c60ecdeb6aa57e7307b04fbad45100514646de62a41757924be54d2ddc503ff5a6b49731a4b50f402578d87e78a1aaa131c96ff74dc526128933a396e259d64dcf9ea312678a4db2c91dfaabfb23fbb34096dc7ab0975c13559e3576d826467b21bc4b5911adb5a872086b3f090c5ebd6f34bee15662ad72305c7d916e919a28878c0069bfc9dd3f67f26f45d589a8c79d0126066c8371830a0024e10d89c6da6ff87652d8b6ca8746e32eaf18b7d2b610dcd82d5168149fe108574d08735f2260c'

    #'keword=&code=&pageNo='
    # headers = {
    #     'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    #     'cache-control': "no-cache",
    #     'postman-token': "6eb8950f-4839-3857-15e9-91a14c7e1663"
    # }

    def __init__(self):
        pass

    def tokens(self):
        self.token = BaseConfig().base_token
        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
        }
        headers['lf-None-Matoh'] = self.token
        return headers

    #post方法
    @property
    @retry(reNum=getYamlfield(gl.configFile)['RETRY']['ReNum'])
    def post(self):
        #url拼接
        self.full_url = BaseConfig().app_url + self.Url

        #发送post请求
        res = requests.request("POST",
                               self.full_url,
                               data=self.payload,
                               headers=self.tokens())
        return res.text
Ejemplo n.º 7
0
class HttpcheckRequest(object):
    Url = "/check/user/smsCode"

    payload = '80a0ded12abc20e5a332b6bc234ef20f1eb48ab77c5b8fc915e1fd892e418c85'

    #'keword=&code=&pageNo='
    # headers = {
    #     'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    #     'cache-control': "no-cache",
    #     'postman-token': "6eb8950f-4839-3857-15e9-91a14c7e1663"
    # }

    def __init__(self):
        pass

    def tokens(self):
        self.token = BaseConfig().base_token
        headers = {
            'Content-Type': "application/json",
            'cache-control': "no-cache",
        }
        headers['lf-None-Matoh'] = self.token
        return headers

    #post方法
    @property
    @retry(reNum=getYamlfield(gl.configFile)['RETRY']['ReNum'])
    def post(self):
        #url拼接
        self.full_url = BaseConfig().check_url + self.Url

        #发送post请求
        res = requests.request("POST",
                               self.full_url,
                               data=self.payload,
                               headers=self.tokens())
        return res.text
Ejemplo n.º 8
0
class Httpupdata(object):
    #url信息
    Url = "/machine/machine/installApp"
    updataUrl = "/machine/machine/updateInfo"

    #机器信息
    machineId = ['c2f5a701a5244d158ceb5cbba8d8e16a','4b5ad3fc4afb4f09a3cadd1220b79781','decd4822d8d244bb8301de02a3fbcccb']
    for newmachineId in machineId:
        print newmachineId


    datas = {"appPackageName":"com.inno72.detection","url":"http://inno72.oss.72solo.com/apk/test/test_detection.apk","versionCode":"6"}

    datas = {"appPackageName":"com.inno72.installer","url":"http://inno72.oss.72solo.com/apk/test/prod_installer.apk","versionCode":"2"}

    datas = {"appPackageName":"com.inno72.monitor","url":"http://inno72.oss.72solo.com/apk/test/prod_monitor.apk","versionCode":"4"}

    datas = {"appPackageName":"com.inno72.upload","url":"http://inno72.oss.72solo.com/apk/test/prod_upload.apk","versionCode":"3"}

    #数据信息
    updatas = {"machineId":newmachineId,"updateStatus":"3"}
    # payload = {"machineId":'c2f5a701a5244d158ceb5cbba8d8e16a',"appPackageName":datas['appPackageName'],"url":datas['url'],"versionCode":datas['versionCode']}


    def __init__(self):
        pass


    def tokens(self):
        self.token = BaseConfig().base_token
        headers = {
            'Content-Type': "application/x-www-form-urlencoded",
            'cache-control': "no-cache",
        }
        headers['lf-None-Matoh'] = self.token
        return headers

    #post方法
    @property
    @retry(reNum=getYamlfield(gl.configFile)['RETRY']['ReNum'])
    def post(self):
        #url拼接
        self.full_url = BaseConfig().base_url + self.Url

        #发送post请求
        res = requests.request("POST",self.full_url,data=self.payload,headers=self.tokens())
        if res.status_code ==200:
            return res.text
        else:
            return {"errcode": 9001, "errmsg": str(res)}

    @property
    def updata(self):
        #url拼接
        self.full_url = BaseConfig().base_url + self.updataUrl

        #发送post请求
        updatares = requests.request("POST",self.full_url,data=self.updatas,headers=self.tokens())
        if updatares.status_code ==200:
            return  updatares.text
        else:
            return {"errcode": 9001, "errmsg": str(updatares)}
Ejemplo n.º 9
0
    def send(self):
        self.curDateTime = str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
        print self.curDateTime
        self.config = scripts.getYamlfield(os.path.join(gl.configPath, 'config.yaml'))
        # 发件人地址,通过控制台创建的发件人地址
        self.username = self.config['EMAIL']['Smtp_Sender']
        # 发件人密码,通过控制台创建的发件人密码
        self.password = self.config['EMAIL']['Password']
        # 自定义的回复地址
        self.replyto = '***'
        # 收件人地址或是地址列表,支持多个收件人,最多30个
        # rcptto = ['***', '***']
        list = self.config['EMAIL']['Receivers']
        self.rcptto =', '.join(list)
        self.msg_title = self.config['EMAIL']['Msg_Title']
        # 构建alternative结构
        msg = MIMEMultipart('alternative')
        # msg['Subject'] = Header('点72接口自动化测试'.decode('utf-8')).encode()
        msg['Subject'] = Header('%s%s' % (self.msg_title, self.curDateTime), 'utf-8')
        msg['From'] = '%s <%s>' % (Header('接口自动化测试'.decode('utf-8')).encode(), self.username)
        msg['To'] = self.rcptto
        msg['Reply-to'] = self.replyto
        msg['Message-id'] = email.utils.make_msgid()
        msg['Date'] = email.utils.formatdate()
        # 构建alternative的text/plain部分
        textplain = MIMEText('自动化测试文本', _subtype='plain', _charset='UTF-8')
        msg.attach(textplain)
        # 构建alternative的text/html部分
        # texthtml = MIMEText('本次自动化测试结果,详情请见附件!', _subtype='html', _charset='UTF-8')
        # msg.attach(texthtml)

        reportfile = os.path.join(gl.reportPath, 'Report.html')
        # 增加邮件内容为html
        fp = open(reportfile, 'rb')
        reportHtmlText = fp.read()
        msg.attach(MIMEText(reportHtmlText, 'html', 'utf-8'))
        fp.close()

        ctype = 'application/octet-stream'
        maintype, subtype = ctype.split('/', 1)
        # 增加后台接口附件
        file = MIMEBase(maintype, subtype)
        file.set_payload(reportHtmlText)
        file.add_header('Content-Disposition', 'attachment', filename='Report.html')
        encoders.encode_base64(file)
        msg.attach(file)
        #增加游戏报告附件
        filegame = MIMEBase(maintype, subtype)
        filegame.set_payload(reportHtmlText)
        filegame.add_header('Content-Disposition', 'attachment', filename='gameReport.html')
        encoders.encode_base64(filegame)
        msg.attach(filegame)

        # 发送邮件
        try:
            client = smtplib.SMTP()
            # python 2.7以上版本,若需要使用SSL,可以这样创建client
            # client = smtplib.SMTP_SSL()
            # SMTP普通端口为25或80
            client.connect('smtpdm.aliyun.com', 25)
            # 开启DEBUG模式
            client.set_debuglevel(0)
            client.login(self.username, self.password)
            # 发件人和认证地址必须一致
            # 备注:若想取到DATA命令返回值,可参考smtplib的sendmaili封装方法:
            #      使用SMTP.mail/SMTP.rcpt/SMTP.data方法
            client.sendmail(self.username, self.rcptto, msg.as_string())
            client.quit()
            print '邮件发送成功!'
        except smtplib.SMTPConnectError, e:
            print '邮件发送失败,连接失败:', e.smtp_code, e.smtp_error