python字典中用于http头构造的变量

python字典中用于http头构造的变量,python,dictionary,python-requests,Python,Dictionary,Python Requests,python新手,但我尝试在字典中使用一个变量,用于构造http头 这就是我所拥有的: import requests url = "https://sample.com" auth = "sampleauthtoken" headers = { 'authorization': "Bearer "<VARIABLE auth HERE>, 'cache-control': "no-cache" } response = requests.reques

python新手,但我尝试在字典中使用一个变量,用于构造http头

这就是我所拥有的:

import requests

url = "https://sample.com"
auth = "sampleauthtoken"


headers = {
    'authorization': "Bearer "<VARIABLE auth HERE>,
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)
导入请求
url=”https://sample.com"
auth=“sampleauthtoken”
标题={
“授权”:“持票人”,
“缓存控制”:“没有缓存”
}
response=requests.request(“GET”,url,headers=headers)
打印(response.text)

我尝试了几种不同的组合,但没有成功

如果我理解正确,您只想使用
+
运算符连接字符串:

import requests

url = "https://sample.com"
auth = "sampleauthtoken"


headers = {
    'authorization': "Bearer " + auth,  # -> "Bearer sampleauthtoken"
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)