I got this snippet out of my text book but it's giving me a type error, I'll just give you the whole code, tell me if you get it too, if you would.
import urllib.request
import math
whips=int(0)
rate=float(4)
while rate <= float(20):
improve= rate*float(.15)+rate
rate= improve
whips=whips+1
print(whips)
def send_to_twitter():
msg = whips
password_manager = urllib.request.HTTPPasswordMgr()
password_manager.add_password("Twitter API","http://twitter.com/statuses", "jcbamm26", "~~~~~~~")
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()
send_to_twitter()
the error return is
Traceback (most recent call last):
File "C:\Python32\AB3.py", line 21, in <module>
send_to_twitter()
File "C:\Python32\AB3.py", line 19, in send_to_twitter
resp = urllib.request.urlopen('http://twitter.com/statuses/update.json', params)
File "C:\Python32\lib\urllib\request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "C:\Python32\lib\urllib\request.py", line 367, in open
req = meth(req)
File "C:\Python32\lib\urllib\request.py", line 1066, in do_request_
raise TypeError("POST data should be bytes"
TypeError: POST data should be bytes or an iterable of bytes. It cannot be str.