简体   繁体   中英

How do I do a GET request with multiple headers?

Syntax Error when trying to put multiple headers into my GET Request.

I've tried changing the '' around Content-Type and Authorization to "", because I've seen posts on here involving both of them, but neither seem to work. Here is my code.

import json
import requests
url = 'https://api.website.com/testpost'
headers = {

        'Content-type': 'application/json'
        'Authorization': 'Bearer placeholdertoken'
}
response= requests.get(url, headers=headers)
print(response)

I am supposed to be getting an answer, but I'm getting a syntax error at the ":" after authorization

您没有在关键值对后面加上逗号

headers = {

        'Content-type': 'application/json'
        'Authorization': 'Bearer placeholdertoken'
}

That is not correct syntax for creating the dictionary.. you are missing a comma between the key: value pairs.

Update your code to add a comma, like this:

headers = {
    'Content-type': 'application/json',
    'Authorization': 'Bearer placeholdertoken'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM