#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Need help with a send to twitter function


    In my book, there is a function to send a tweet to twitter that I can't seem to get to work... the code is as follows:
    Code:
    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",
                                                      "TWITTERURL/statuses", "username", "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("TWITTERURL/statuses/update.json", params)
        resp.read()
    I've even tried stripping out the rest of my code and simply calling send_to_twitter() and it's still throwing errors... anyone have any idea what's going on?

    Since I can't post urls, i changed the urls to TWITTERURL... also, everything is indented like it should be... its just hard to do on a forum.....
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,703
    Rep Power
    480
    Whoever can answer this question might like to know what the errors are. At a glance the python syntax looks correct.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo