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

    Join Date
    May 2013
    Rep Power

    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:
    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)
        params = urllib.parse.urlencode( {'status': msg} )
        resp = urllib.request.urlopen("TWITTERURL/statuses/update.json", params)
    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 God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    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