模板无效

时间:2017-02-03 13:41:36

标签: python-2.7

我正在尝试发送短信,我正在这样做

{"错误":[{"代码":80,"消息":"无效模板"}],&#34 ;状态":"失效"}

我的代码是:

def sending_sms(number,message):

   url = 'http://api.textlocal.in/send/'
   msg = message
   post_fields=({"username":"*********","password":"******","numbers":number,"message":msg})
   request = Request(url, urlencode(post_fields).encode())
   print request
   json = urlopen(request).read().decode()
   print json
   return json

1 个答案:

答案 0 :(得分:0)

requests library很容易用于此类任务。

import requests


def sending_sms(number,message):
    url = 'http://api.textlocal.in/send/'

    post_fields = {
        "username": "*********",
        "password": "******",
        "numbers": number,
        "message": message
    }

    response = requests.post(url, data=post_fields)

    json = response.json()
    print json

    return json