What's wrong with this python code?

0
import urllib.request
import time

def send_to_twitter():
    import sys
    import tweepy
    CONSUMER_KEY = '1wrnsF5lB8fEWVzRdvlIqdTl'
    CONSUMER_SECRET = 'eTiylDUHLJgGnTCcxzzCtzHXG4OlHrbY6wLvuZUnAEhrokyNA'
    ACCESS_KEY = '2325915097-q2JYaZ3UGeL9Pr95BJC7643NMyETY6x7Bb8T1q'
    ACCESS_SECRET = '8GRq4e9ukVKcC8XjroM3iLKuZYOM2QtFEdCHXG3TXx0z'
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
    api = tweepy.API(auth)
    api.update_status(msg)

def get_price():
    page = urllib.request.urlopen("http://beans-r-us.appspot.com/prices-loyalty.html")
    text = page.read().decode("utf8")
    where = text.find('>$')
    start_of_price = where + 2
    end_of_price = start_of_price + 4
    return(text[start_of_price : end_of_price])

escolha = input("Precisa do valor imediatamente? ")

if escolha == 'y':
    send_to_twitter(get_price())
else:
    if escolha == 'n':
        price = 99.99
        while price > 4.74:
            price = float(get_price())
            time.sleep(3)
        send_to_twitter('BUY!')
    else:
        print("Voce nao escolheu nada")

Error message:

Traceback (most recent call last):
  File "(livro)programa_com_escolha_cafe.py", line 34, in <module>
    send_to_twitter('BUY!')
TypeError: send_to_twitter() takes 0 positional arguments but 1 was given
    
asked by anonymous 06.01.2017 / 16:30

1 answer

6

Your code is producing the following error:

TypeError: send_to_twitter() takes 0 positional arguments but 1 was given

Looking at the message, we see that this is a TypeError , which tells us that the send_to_twitter() function should get 0 arguments, however, you passed 1 argument by typing the term 'BUY!' , within send_to_twitter('BUY!') .

At the beginning of the code, we see that the send_to_twitter() function was created without asking for any arguments.

Try changing the snippet:

def send_to_twitter():
    import sys
    import tweepy
    ...

for

def send_to_twitter(msg):
    import sys
    import tweepy
    ...

Exemplifying ...

Wrong:

def imprimirNaTela():
    print msg

Correct:

def imprimirNaTela(msg):
    print msg
    
06.01.2017 / 16:49