Page 142 -
P. 142
functions
This is the start of the program. Write a modified version of this
code that will allow the send_to_twitter() function to see
the password variable.
Hint: you might not need to use a function.
import urllib.request
import time
def set_password(): You need to rewrite this section.
password="C8H10N4O2"
set_password()
def send_to_twitter(msg):
password_manager = urllib.request.HTTPPasswordMgr()
password_manager.add_password("Twitter API",
"http://twitter.com/statuses", "starbuzzceo", password)
http_handler = urllib.request.HTTPBasicAuthHandler(password_manager)
page_opener = urllib.request.build_opener(http_handler)
urllib.request.install_opener(page_opener)
params = urllib.parse.urlencode( {'status': msg} )
resp = urllib.request.urlopen("http://twitter.com/statuses/update.json", params)
resp.read()
Write your new
version here.
you are here 4 107