amigos, queria saber si podrian determinar porque el siguiente codigo no funciona, porque la verdad que no tiene logica, todo lo veo perfecto, no soy tan experimentado en python, a ver si ustedes pueden ayudarme, de antemano muchas gracias.
Código Python:
Ver originalimport urllib.request
import time
password="yourpass"
def send_to_twitter(msg):
password_manager = urllib.request.HTTPPasswordMgr()
password_manager.add_password("Twitter API",
"http://twitter.com/statuses", "YourUsername", 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()
def get_price():
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
text = page.read().decode("utf8")
where = text.find('>$')
start_of_price = where + 2
end_of_price = start_of_price + 4
return float(text[start_of_price:end_of_price])
price_now = input("Do you want to see the price now (Y/N)? ")
if price_now == "Y":
send_to_twitter(get_price())
else:
price = 99.99
while price > 4.74:
time.sleep(900)
price = get_price()
send_to_twitter("Buy!")
y aqui el error que me muestra el interprete
Traceback (most recent call last):
File "C:\Users\Marino\Documents\Pycode\hfprog_resources \Chapter 3\page108.py", line 28, in <module>
send_to_twitter(get_price())
File "C:\Users\Marino\Documents\Pycode\hfprog_resources \Chapter 3\page108.py", line 14, 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 364, in open
req = meth(req)
File "C:\Python32\lib\urllib\request.py", line 1052, 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.