成功登录后,Python请求获得401

时间:2015-02-19 02:46:04

标签: python python-requests

我正在尝试从需要登录的网站获取一些数据。我尝试获取python请求Session,我可以使用post登录。但是在成功登录第二个请求(get)之后,我会给我一个401.有趣的是,相同的代码在一个主机上运行但不在另一个主机上运行。主机是相同的。有谁知道可能是什么问题?下面是我写的python中的代码片段。我正在使用python 2.7并请求版本2.0。

session = requests.Session()
session.auth = (self.userName, self.password)
session.proxies = self.proxyInformation   # {'http' : http://<zyz>, 'https' : https://xyz}

response = session.post(self.url)
print "response = ", response.status_code   # Gets 200
soup = BeautifulSoup(response.content)

boxResponse = soup.find('div', attrs= {'class' : 'boxContent'})

for data in boxResponse.select("p a"):
    hrefLink = data['href']
    if hrefLink is None:
        continue

    print "hrefLink = ", hrefLink
    print self._NAME, " : Processing {0}".format(hrefLink)

    dataResponse = session.get(hrefLink)
    print "dataResponse = ", dataResponse    # Gets 401

0 个答案:

没有答案
相关问题