Guest User

Untitled

a guest
Sep 13th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/usr/bin/python
  2. #-*- coding: UTF-8 -*-
  3. import base64
  4. import httplib, urllib
  5.  
  6. class FanfouClient:
  7. _username = ""
  8. _password = ""
  9. _authStr = ""
  10.  
  11. def __init__(self,username,password):
  12. self._username = username
  13. self._password = password
  14. self._authStr = base64.b64encode(username + ":" + password);
  15. #饭否API使用HTTP Basic认证,用户名和密码用base64编码
  16. print "[Authentication][Encoded] ", self._authStr
  17.  
  18. def sendMessage(self,message):
  19. headers = {"Content-type": "application/x-www-form-urlencoded",
  20. "Accept": "text/xml",
  21. "Authorization": "Basic " + self._authStr}
  22. params = urllib.urlencode({"status": message})
  23. conn = httplib.HTTPConnection("api.fanfou.com")
  24. conn.request("POST","/statuses/update.xml",params,headers)
  25. response = conn.getresponse()
  26. print "Return code:", response.status, " reason:", response.reason
  27. if response.status == 200:
  28. print "Message successfully sent."
  29. else:
  30. print "Error sending message,check your account"
  31.  
  32.  
  33. if __name__ == "__main__":
  34. username = ''
  35. password = ''
  36. msg = ""
  37. while msg == "":
  38. msg = raw_input("Input some message:")
  39. client = FanfouClient(username,password)
  40. client.sendMessage(msg)
Add Comment
Please, Sign In to add comment