Created
February 20, 2014 02:24
-
-
Save Kevinstronger/9105889 to your computer and use it in GitHub Desktop.
Tweet on Python by http://www.supertweet.net/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib | |
import base64 | |
import string | |
import urllib | |
host = "api.supertweet.net" | |
url = "/1.1/statuses/update.json" | |
username = 'INPUTUSERNAME' | |
password = 'INPUTPASSWORD' | |
message = 'Tweet by Python on Raspberry Pi' | |
# base64 encode the username and password | |
auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') | |
body = urllib.urlencode({'status': message}) | |
webservice = httplib.HTTP(host) | |
# write your headers | |
webservice.putrequest("POST", url) | |
webservice.putheader("Host", host) | |
webservice.putheader("User-Agent", "Python http auth") | |
webservice.putheader("Content-type", "application/x-www-form-urlencoded") | |
webservice.putheader("Content-length", "%d" % len(body)) | |
# write the Authorization header like: 'Basic base64encode(username + ':' + password) | |
webservice.putheader("Authorization", "Basic %s" % auth) | |
webservice.endheaders() | |
webservice.send(body) | |
# get the response | |
statuscode, statusmessage, header = webservice.getreply() | |
print "Response: ", statuscode, statusmessage | |
print "Headers: ", header | |
res = webservice.getfile().read() | |
print 'Content: ', res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment