本来想第一篇文章写算法,或者风控模型之类的内容,先写了这个吧,实际工作中遇到的小问题
data_json = {'email': sys.argv[1],'wxtext':sys.argv[2]}print (urllib.parse.urlencode(data_json))print (json.dumps(data_json))
两种编码方式完全不同,踩坑mark
#!/usr/bin/env python# -*- coding:utf-8 -*-import sys,jsonimport urllib.requestimport urllib.parseurl = 'http://mcloud./wx/emailsendtext'data_json = {'Email': sys.argv[1],'WXText':sys.argv[2]}def http_post(url,data_json):jdata = bytes(json.dumps(data_json),encoding='utf8')response = urllib.request.urlopen(url,jdata)return response.read()if __name__ == "__main__":http_post(url,data_json)