diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 35fb90c..34fadfa 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,6 +5,8 @@ + + @@ -19,9 +21,9 @@ - + - + @@ -190,8 +182,8 @@ @@ -203,10 +195,10 @@ DEFINITION_ORDER - @@ -248,7 +240,7 @@ - + @@ -291,7 +283,7 @@ - + @@ -315,7 +307,7 @@ - + - + - + - + @@ -753,13 +745,6 @@ - - - - - - - @@ -1032,42 +1017,48 @@ - + - - + + - + - - - + + - + - - + + - + + + + + + + + - - + + @@ -1080,28 +1071,28 @@ - - - - - - - - - - + + + + + + + + + + - - + + diff --git a/app/models/test.db b/app/models/test.db index f74ec07..781db03 100644 Binary files a/app/models/test.db and b/app/models/test.db differ diff --git a/app/tools/http_email.py b/app/tools/http_email.py index aff9083..4b1506c 100644 --- a/app/tools/http_email.py +++ b/app/tools/http_email.py @@ -36,10 +36,11 @@ def unique_id(): return uuid.uuid4().__str__() -def single_mail_api(recipients="", subject="", text=None, html="", method="GET"): +def single_mail_api(recipients=None, subject=None, text=None, html=None, method="GET"): # https://help.aliyun.com/document_detail/29442.html?spm=5176.doc29441.6.567.kBMXeE # paras must be encode with utf-8 # base URL + # issue[fixed]: can't encode html correctly and raise signature don't match error base_http_url = " http://dm.aliyuncs.com/" base_https_url = " https://dm.aliyuncs.com/" @@ -71,8 +72,11 @@ def single_mail_api(recipients="", subject="", text=None, html="", method="GET") params_keys.sort() params_str = '' # 对value进行URL编码后拼接为字符串,key原则上需要,但因为全部是英文字母故略去 + # 注意"/"也需要URL编码,使用urllib.quote_plus()会导致空格转换成+而非%20, + # 而使用urllib.quote需要取消safe,因为"/"不会被编码 + # 如果字符串不符合要求,签名计算无法通过 for key in params_keys: - params_str += key + '=' + urllib.quote_plus(str(public_params[key])) + '&' + params_str += key + '=' + urllib.quote(str(public_params[key]), safe="") + '&' # 别忘记去掉最末的& params_str_encoded = urllib.quote(params_str[:-1]) @@ -104,6 +108,15 @@ def single_mail_api(recipients="", subject="", text=None, html="", method="GET") raise HttpMethodException("HTTP Method Unsupported.") if __name__ == "__main__": - single_mail_api(recipients=u"datingwithme@live.cn", - subject=u"Python发送邮件", - html=u"Python通过HTTP方式发送邮件") \ No newline at end of file + html = """ + + +

测试测试 空格

+ + + """ + print(unicode(html, "utf-8")) + print(type(html)) + single_mail_api(recipients="datingwithme@live.cn", + subject="Python发送邮件", + html=html) \ No newline at end of file diff --git a/app/tools/tasks.py b/app/tools/tasks.py index 2a4cb60..4e30de6 100644 --- a/app/tools/tasks.py +++ b/app/tools/tasks.py @@ -61,7 +61,7 @@ def send_mail_by_http(self, raw_msg): print("mail at debug model will not be sent!") else: try: - single_mail_api(recipients=raw_msg["recipients"], subject=raw_msg["subject"], html=raw_msg["html"]) + single_mail_api(recipients=raw_msg["recipients"], subject=raw_msg["subject"], html=unicode(raw_msg["html"])) except HttpMailSendException as e: self.retry(exc=e) except Exception as e: diff --git a/start_celery.bat b/start_celery.bat index 1702c0d..a0d599b 100644 --- a/start_celery.bat +++ b/start_celery.bat @@ -1,5 +1,5 @@ @echo off set "d=%cd%" call "%d%\venv\Scripts\activate.bat" -python -m celery -A app.tools.tasks.celery worker --loglevel=info +python -m celery -A app.tools.tasks.celery worker --loglevel=debug pause \ No newline at end of file