ich lerne mit HeadFirst Programming bei dem ja bekanntlich Python nähergebracht wird.
Nun sitze ich gerade schon einige Zeit an einem Prob:
Code: Alles auswählen
import urllib.request
import time
def send_to_twitter(msg):
password_manager = urllib.request.HTTPPasswordMgr()
password_manager.add_password("Twitter API",
"http://twitter.com/statuses", "MeinName", "MeinPasswort")
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()
def get_price():
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
text = page.read().decode("utf8")
where = text.find('>$')
sotp = where [code=python]+ 2
eotp = sotp + 4
return float(text[sotp:eotp])
pn = input("Do you want to so the price now (Y/N)? ")
if pn == "Y":
send_to_twitter(get_price())
else:
price = 99.99
while price > 4.74:
time.sleep(5)
price = get_price()
send_to_twitter("Buy!")
Das ist das Prob:
Code: Alles auswählen
raceback (most recent call last):
File "/home/jason/Python_Project/FirstHead/buzzbeans_6step.py", line 25, in <module>
send_to_twitter(get_price())
File "/home/jason/Python_Project/FirstHead/buzzbeans_6step.py", line 12, in send_to_twitter
resp = urllib.request.urlopen("http://twitter.com/statuses/update.json", params)
File "/usr/lib/python3.2/urllib/request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.2/urllib/request.py", line 367, in open
req = meth(req)
File "/usr/lib/python3.2/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.
Danke im Voraus
PS: k.a. wie ich die Einrückung einstellen kann, sofern es hier eine gibt
