Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3.  
  4. import urllib2
  5.  
  6. getFunction = 'http://127.0.0.1:8000/GPIO/4/function'
  7. setOutput =  'http://127.0.0.1:8000/GPIO/4/function'
  8. setPulse = 'http://127.0.0.1:8000/GPIO/4/pulse/'
  9.  
  10. passMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
  11. passMgr.add_password(None, 'http://127.0.0.1:8000/', 'webiopi', 'raspberry')
  12. authHandler = urllib2.HTTPBasicAuthHandler(passMgr)
  13. opener = urllib2.build_opener(authHandler)
  14. urllib2.install_opener(opener)
  15.  
  16. function = urllib2.urlopen(getFunction).read()
  17.  
  18. if function != 'OUT':
  19.   urllib2.urlopen(setOutput, '').read()
  20.  
  21. data = urllib2.urlopen(setPulse, '').read()
  22.  
  23. print "Content-Type: text/html\n\n<h1>ring! "+function+"</h1>"