到目前为止我的代码:
import requests
import json
url = "https://stream.twitter.com/1/statuses/sample.json"
r = requests.get(url, auth = ('username', 'password'))
print r.status_code
当我在控制台中运行此脚本时,它一直挂起,但是当我运行等效的 urllib2 时,我得到了很好的响应:
from urllib2 import *
password_mgr = HTTPPasswordMgrWithDefaultRealm()
url = "https://stream.twitter.com/1/statuses/sample.json"
password_mgr.add_password(None, url, 'username', 'password')
h = HTTPBasicAuthHandler(password_mgr)
opener = build_opener(h)
page = opener.open(url)
print page.getcode()
这返回200
。有人知道问题是什么吗?
编辑:另外,当我在上面的代码中调整密码时,我得到了适当的401
响应。我认为这是因为发生了一些阻塞?