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", "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("http://twitter.com/statuses/update.json", params) resp.read()
當我通過IDLE執行此代碼時,出現錯誤;Twitter,錯誤:urllib.error.HTTPError:HTTP錯誤401:未授權
urllib.error.HTTPError: HTTP Error 401: Unauthorized
我的代碼可能有問題嗎?
這是必須用錯誤的用戶名或密碼做些什麼.. – Dananjaya 2010-09-19 07:10:42