variable in python dictionary for http header construction
Question: New to python but I'm trying to use a variable within a dictionary that is
used to construct a http header

This is what I have:

    
    
    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)
    

I have tried a few different combinations with no luck


Answer: If I understand you correctly you just want to concatenating the strings using
the `+` operator:

    
    
    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)
    

