Python将请求POST标头发送给客户端(vuejs)

时间:2020-06-15 14:51:31

标签: python vue.js post header authorization

我正在尝试使用python发出POST请求。

我想传递带有标头的json数据,该标头包含"Authorization": Bearer XXXXXX

我的代码如下:

import requests
import json
access_token = 'xxxxxxxxx'
    payload = {'source': '0'}
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + access_token,
        'user_id' : '2'
    }
    req = requests.Request('POST','https://otherdomain.com/add',headers=headers,data=json.dumps(payload))
    prepared = req.prepare()
    print(prepared)
    s = requests.Session()
    resp = s.send(prepared,verify=False)
    print(resp.headers)

我打印标题prepared的数据如下:

'Content-Type': 'application/json',
'Authorization': 'Bearer xxxxxxxxx',
'user_id' : '2'
'source': '0'

但是,当我请求POST发送到网址https://otherdomain.com/add时,我签入了inspect element chrome(F12),没有任何标头值(查看附件图像)

我不知道我在哪里错,请帮忙。

Click to view image

0 个答案:

没有答案