Pesquisar na Comunidade
Mostrando resultados para as tags ''#API #Python #Twitter''.
Encontrado 1 registro
-
Boa tarde galera!, Estou com problemas de integração da API do Twitter com minha aplicação do Python. Abaixo encaminho meu código e o error. Código: import urllib.request import time import json import socket import ssl def send_to_twitter(): msg = ("I am a message that will be sent to twitter") password_manager = urllib.request.HTTPPasswordMgr() password_manager.add_password("Twitter API","http://twitter.com/statuses","usuario","senha") 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://beans-r-us.appspot.com/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": #print (get_price()) send_to_twitter() else: price = 99.99 while price >4.74: time.sleep(900) price = get_price() #print ("BUY!") send_to_twitter() Error: Do you want to see the price now (y/n)?y Traceback (most recent call last): File "C:\Python34\Exercicio\BUY.py", line 29, in <module> send_to_twitter() File "C:\Python34\Exercicio\BUY.py", line 16, in send_to_twitter resp = urllib.request.urlopen("http://twitter.com/statuses/update.json",params) File "C:\Python34\lib\urllib\request.py", line 161, in urlopen return opener.open(url, data, timeout) File "C:\Python34\lib\urllib\request.py", line 461, in open req = meth(req) File "C:\Python34\lib\urllib\request.py", line 1112, in do_request_ raise TypeError(msg) TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str. >>>