Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import httplib
- import base64
- import string
- import urllib
- host = "api.supertweet.net"
- url = "/1.1/statuses/update.json"
- username = 'Your_Twitter_Account'
- password = 'SuperTweet_Password'
- message = 'Message Goes Here'
- # 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
Advertisement
Add Comment
Please, Sign In to add comment