【发布时间】:2015-11-05 00:55:39
【问题描述】:
为什么我的会话在我完成身份验证后仍要我进行身份验证?
def main(pswd):
with session() as s:
s.post('url',
auth=('user', pswd),
)
response = s.get('url2', cookies=s.cookies)
print(response.text)
为什么我的会话不持久?
此后控制台正在打印:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
我也可以:
s.get('url', auth=('user', 'login')).text
这会起作用,但是对于第二个 s.get 它将不起作用。我必须再传递一次凭据。
【问题讨论】:
标签: python python-2.7 session python-3.x python-requests