Hello for everybody,I'm new in ZeepMobile,I've tried create one script
with Python for send message.
I've generate one new API_KEY,but my code have several errors.
For recently,I've a 400 Bad Request Error,I don't know why and how !
I've do every thing for get success,but the problem insist.
I've no more idea for this.
I hope anybody could help me,give me any idea or fix my code!
Thanks For all !
Here is my code:
#!/usr/bin/python
import base64
import hmac
import time
import os
import hashlib
from hashlib import sha1 as sha
import httplib, urllib, urllib2
mobile = "657343628"
msg = "hola"
#mobile = raw_input("Enter you phone number: ")
#msg = raw_input("Enter your message: ")
http_date = time.strftime('%a, %d %b %Y %H:%M:%S GMT',time.gmtime())
SECRET_KEY = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
API_KEY = '6e966a48-d4ff-4866-a73c-cdf3003ffa1d'
params = urllib.urlencode([
('user_id',mobile),
('body',msg)
])
#The canonical string is computed by collecting the value of the
Date header,
#your API Key and the current request parameters into a string
canonical_string = API_KEY + http_date + params
print canonical_string
signature =
hmac.new(SECRET_KEY, canonical_string, digestmod=sha)
items_encoded = base64.encodestring(signature.digest()).strip()
conn = httplib.HTTPSConnection("
api.zeepmobile.com:443")
headers = {
"Authorization": "Zeep %s:%s" % (API_KEY, items_encoded),
"Content-Type": "application/x-www-form-urlencoded",
"Date": http_date,
"Content-Length": len(params)
}
conn.debuglevel=1
conn.request("POST", "/messaging/2008-07-14/send_message", params,
headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data
conn.close()
And here is result in terminal:
zqu@econcept11:~/Python_Prueba$ python zeep_mobile.py
6e966a48-d4ff-4866-a73c-cdf3003ffa1dThu, 12 May 2011 09:25:36
GMTuser_id=657343628&body=hola
send: 'POST /messaging/2008-07-14/send_message HTTP/1.1\r\nHost:
api.zeepmobile.com\r\nAccept-Encoding: identity\r\nDate: Thu, 12 May
2011 09:25:36 GMT\r\nContent-Length: 27\r\nContent-Type: application/x-
www-form-urlencoded\r\nAuthorization: Zeep 6e966a48-d4ff-4866-a73c-
cdf3003ffa1d:NXwd4u4iyInpra2kZy25bk6EgE4=\r\n\r\n'
send: 'user_id=657343628&body=hola'
reply: 'HTTP/1.1 400 Bad Request\r\n'
header: Date: Thu, 12 May 2011 09:25:39 GMT
header: Server: Apache/2.2.12 (Ubuntu)
header: X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
header: Cache-Control: no-cache
header: Content-Length: 86
header: Status: 400
header: Vary: Accept-Encoding
header: Connection: close
header: Content-Type: text/plain; charset=utf-8
400 Bad Request
The subscrtiption specified is not active or is blocking access from
your application.
Thanks!