How Can I Send Sms Using Python?


Copy and paste this code into a Python project and save the file as smsSend.py.
Change the Authentication_id and Authentication_key.
Go to the home page, Click on the Authentication Key ID, and a page will display.
Copy and paste the 32-character Authentication ID and 32-character Authentication Key.


import json import requests # mtype 'N' = National phone number / 'I' = International phone number msgp_obj = { 'mtype' : 'N', 'sender' : '+919999999999', 'message' : 'This is a test message from Python...', 'auth_id' : 'Authentication_id', 'auth_key' : 'Authentication_key' } msgpServer_url = 'https://msgpserver.com/api/' headers = { 'Content-Type' : 'application/json; UTF-8', } response = requests.post(msgpServer_url, data=json.dumps(msgp_obj), headers=headers) if response.status_code == 200: json_content = json.loads(response.content) print("json_content: ", json_content) else: print("Server Down... ")

The Server Request Returns All Response Status.


if response.status_code == 200: json_content = json.loads(response.content) print("json_content: ", json_content) status = json_content['status'] login = json_content['login'] recharge = json_content['recharge'] host = json_content['host'] msg = json_content['msg'] print("status: ", status) print("login: ", login) print("recharge: ", recharge) print("host: ", host) print("msg: ", msg) else: print("Server Down... ")

Return Success Response.


[ SUCCESS ] json_content: {'status': 'success', 'login': 'success', 'recharge': 'success', 'host': 'success', 'msg': 'success'}

Return Error Response.


[ ERROR ] json_content: {'status': 'success', 'login': 'success', 'recharge': 'success', 'host': 'error', 'msg': 'error'} json_content: {'status': 'success', 'login': 'success', 'recharge': 'expire', 'host': 'error', 'msg': 'error'} json_content: {'status': 'online', 'login': 'error', 'recharge': 'error', 'host': 'error', 'msg': 'error'}


Are you satisfied this Answer?