Python Twitter,错误:urllib.Error.HTTPError:HTTP错误401:未经授权 def发送到twitter(): msg=“我是一条将发送到Twitter的消息” password\u manager=urllib.request.HTTPPasswordMgr() 密码管理器。添加密码(“Twitter API”, "http://twitter.com/statuses“,”用户名“,”密码“) http\u handler=urllib.request.HTTPBasicAuthHandler(密码管理器) page\u opener=urllib.request.build\u opener(http\U处理程序) urllib.request.install\u opener(第页\u opener) params=urllib.parse.urlencode({'status':msg}) resp=urllib.request.urlopen(“http://twitter.com/statuses/update.json“,参数) resp.read()

Python Twitter,错误:urllib.Error.HTTPError:HTTP错误401:未经授权 def发送到twitter(): msg=“我是一条将发送到Twitter的消息” password\u manager=urllib.request.HTTPPasswordMgr() 密码管理器。添加密码(“Twitter API”, "http://twitter.com/statuses“,”用户名“,”密码“) http\u handler=urllib.request.HTTPBasicAuthHandler(密码管理器) page\u opener=urllib.request.build\u opener(http\U处理程序) urllib.request.install\u opener(第页\u opener) params=urllib.parse.urlencode({'status':msg}) resp=urllib.request.urlopen(“http://twitter.com/statuses/update.json“,参数) resp.read(),python,twitter,Python,Twitter,当我通过IDLE执行这段代码时,我得到了如下错误: 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", "user

当我通过IDLE执行这段代码时,我得到了如下错误:

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() urllib.error.HTTPError:HTTP错误401:未经授权 我的代码可能有什么问题?

Twitter。您应该使用oauth代替


如果你想从python开始使用twitter,这似乎是一个不错的库:它是最新的,支持誓言,看起来非常完整。

你使用的是旧的HTTP Auth方法。使用OAuth升级

转到以下链接以设置您的Twitter应用程序: (提示:出于测试目的,您可以将URL设置为127.0.0.1,并记住将应用程序设置为浏览器并指定回调URL)


您可以从那里继续。

这与错误的用户名或密码有关。。 urllib.error.HTTPError: HTTP Error 401: Unauthorized