使用python请求库针对使用Bearer令牌的Web应用发出发布请求

时间:2020-08-16 10:33:25

标签: python python-3.x authentication http-post bearer-token

我正在尝试使用python请求库向使用Bearer令牌进行身份验证的网站进行POST请求。这是我的代码:

sess = requests.session()
post_url = 'someURL'
payload = {'username': 'myusername',
           'password': 'mypassword'}
post_header = {'Authentication': f'Bearer {token_value}'}    
r = sess.post(url_post, data=payload, headers=post_header)

with open('index.html', 'w', encoding="utf-8") as f:
    f.write(r.text)

作为回应,我再次获得登录页面,其状态码为200。
我还在post函数中尝试了 auth 参数,但没有一个起作用。
有人知道我该怎么办?

0 个答案:

没有答案