HTTPS POST in Python for Sending Messages
I'm having trouble doing a HTTPS POST in Python using httplib to POST to the imified api resource.
Code is below:
import httplib, urllib
username = 'username'
password = 'password'
resource = 'https://www.imified.com/api/bot'
params = urllib.urlencode({'botkey':'XXXXX-XXXXXX-XXXXXXX' , 'apimethod':'send', 'userkey':'XXXXXX-XXXXXX-XXXXXXX', 'msg':'hello'})
base64string = base64.encodestring('%s:%s' % (username, password))
authString = 'Basic %s' % base64string
headers = {"AUTHORIZATION" : authString}
conn = httplib.HTTPSConnection('imified.com:443')
req = conn.request("POST", "/api/bot", params, {})
response = conn.getresponse()
I end up getting a 405 Method Not Allowed. Any ideas? I don't want to use Google App Engine to use a proxy. This seems like the only way as urllib2 doesn't seem to recognize 'https' URLs. Has anyone used httplib to successfully make the HTTPS call to the resource with basic authentication?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Adam Kalsey on 20 Jun, 2009 02:47 PM
Any python developers around that can help Jingsong out?
3 Posted by Jingsong Wang on 20 Jun, 2009 11:21 PM
I used my browser to request http://imified.com/api/bot and I got a secure connection failed error in FireFox 3.0.11.
Per my browser:
imified.com uses an invalid security certificate. The certificate is only valid for www.imified.com (Error code: ssl_error_bad_cert_domain)
Something wrong with SSL? Is there a way to make the API exposed not through SSL as it's causing me quite the headache..
4 Posted by Anonymous on 20 Jun, 2009 11:24 PM
Try https://www.imified.com/api/bot
// Anthony
5 Posted by Jingsong Wang on 20 Jun, 2009 11:50 PM
Yeah, tried that too.
Here's my modified code (I think I've tried every way to make a HTTPS
request in Python now, short of using a proxy):
#### ... data params and auth headers set here ...
conn = httplib.HTTPSConnection('www.imified.com:443')
httplib.HTTPSConnection.connect(conn)
conn.putrequest("POST", "/api/bot")
conn.putheader("Content-Length", len(base64string))
conn.putheader("AUTHORIZATION", authString)
conn.endheaders()
conn.send(params)
response = conn.getresponse()
I still get a 405 Method Not Allowed, and I know that the headers and params
are sending fine, because at first I left out 'Content-Length', and I got a
411 Length Required code.
Any ideas?
Support Staff 6 Posted by Adam Kalsey on 21 Jun, 2009 05:11 PM
Since there's another thread going about this, I'm closing this one.
The other thread is at http://help.imified.com/discussions/problems/17-post-not-allowed-at-httpswwwimifiedcomapibot
Adam Kalsey closed this discussion on 21 Jun, 2009 05:11 PM.