为什么cookie(在Postman应用程序中显示)不会显示在Python响应变量中?

时间:2018-06-02 19:45:31

标签: python cookies python-requests postman

https://open.spotify.com/search/results/cheval是触发各种中间请求的链接,其中一个是下面的尝试请求。

在Postman(Chrome插件)中运行以下请求时,会显示响应cookie(13),但在Python中运行此请求时似乎不存在(response.cookies为空)。我也尝试过使用会话,但结果相同。

更新尽管在使用Selenium后检索了这些Cookie(登录/解析验证码并将登录Cookie转移到会话以用于以下请求,但仍然不知道需要哪些变量?对于与该请求一起返回的目标cookie)。

如何使用Python检索这些响应cookie(如果有的话)?

url = "https://api.spotify.com/v1/search"

querystring = {"type":"album,artist,playlist,track","q":"cheval*","decorate_restrictions":"true","best_match":"true","limit":"50","anonymous":"false","market":"from_token"}

headers = {
    'access-control-request-method': "GET",
    'origin': "https://open.spotify.com",
    'x-devtools-emulate-network-conditions-client-id': "0959BC056CD6303CAEC3E2E5D7796B72",
    'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
    'access-control-request-headers': "authorization",
    'accept': "*/*",
    'accept-encoding': "gzip, deflate, br",
    'accept-language': "en-US,en;q=0.9",
    'cache-control': "no-cache",
    'postman-token': "253b0e50-7ef1-759a-f7f4-b09ede65e462"
    }

response = requests.request("OPTIONS", url, headers=headers, params=querystring)

print(response.text)

0 个答案:

没有答案