【发布时间】:2021-04-02 16:40:48
【问题描述】:
我正在尝试登录一个网站,并获得一个特定的 GET 请求,但是,我不确定我是否正确执行此操作。我会解释一些细节。
网站设置如下: 登录页面:example.com/something/login 登录时发送的帖子请求 URL:example.com/something/token 和我需要的 GET 请求:URL:website.com/something/info
我的问题是我的代码似乎没有让我登录,因为当我尝试获取 website.com/something/info 时它返回响应 401。我不确定我的代码是否没有发送有效负载,或者我的代码是不正确。
我的问题也可能是我使用了错误的 URL。我正在使用example.com/something/login,但我不确定是否应该使用example.com/something/login 或example.com/something/token(我登录时似乎发送的内容)
另外我应该链接token的请求载荷:
grant_type=password&username=MYUSERNAME&password=MYPASSWORD&scope=3
import requests
with requests.Session() as session:
session.post("example.com/something/login"), data={
'grant_type':'password',
'username':'MYUSERNAME',
'password':'MYPASSWORD',
'scope':'3'
})
print(session.get("example.com/something/info"))
【问题讨论】: