API request response.headers
shows as below:
Headers([(‘server’, ‘nginx’), (‘content-type’, ‘application/json’), (‘content-length’, ’86’), (‘content-encoding’, ‘gzip’), (‘bd-tt-error-code’, ‘0’), (‘vary’, ‘Accept-Encoding,Origin’), (‘x-tt-logid’, ‘202312170838402529F37099A87D3183C8’), (‘x-tt-store-idc’, ‘useast50’), (‘x-tt-store-region’, ‘us’), (‘x-tt-store-sec-uid’, ‘MS4wLjABAAAANwkJuWIRFOzg5uCpDRpMj4OX-QryoDgn-yYlXQnRwQQ’), (‘tt-idc-switch’, ‘10000@20231215031610’), (‘access-control-expose-headers’, ‘tt-idc-switch’), (‘server-timing’, ‘inner; dur=342’), (‘x-tt-trace-host’, ‘018d3bc5ced77196494af1e4061407934b6217a2456ca5e45c0b073ee97f5212289640d2a2b1270fb44af17fcd1630e811046af8087a2cdb115aac237560ac99f7402ce7cc4f5d05098607026e881fdf7a0710ec3d4cb1e8a49b9a5b4a22c714be’), (‘x-tt-trace-id’, ’00-76ed61b410657ea68d8c17862b9504d1-76ed61b410657ea6-01′), (‘date’, ‘Sun, 17 Dec 2023 08:38:40 GMT’), (‘x-cache’, ‘TCP_MISS from server.com (AkamaiGHost/11.3.3-52668873) (-)’), (‘set-cookie’, ‘passport_csrf_token=d5df6670ecf03e53fd2aabba1b0b1bcb; Path=/; Domain=API.com; Max-Age=5184000; Secure; SameSite=None’), (‘set-cookie’, ‘passport_csrf_token_default=d5df6670ecf03e53fd2aabba1b0b1bcb; Path=/; Domain=API.com; Max-Age=5184000’), (‘set-cookie’, ‘reg-store-region=; Path=/; Domain=API.com; Max-Age=0; HttpOnly; Secure’), (‘set-cookie’, ‘store-idc=useast50; Path=/; Domain=API.com; Max-Age=31536000; HttpOnly’), (‘set-cookie’, ‘store-country-code=us; Path=/; Domain=API.com; Max-Age=31536000; HttpOnly’), (‘set-cookie’, ‘store-country-code-src=did; Path=/; Domain=API.com; Max-Age=31536000; HttpOnly’), (‘set-cookie’, ‘tt-target-idc=useast50; Path=/; Domain=API.com; Max-Age=31536000; HttpOnly’), (‘set-cookie’, ‘tt-target-idc-sign=J1Ng0zaiTksaUHc72e3Eak8RycLDh7UkApISS4T6-R4xWqBERvLKb8xTEUGnto-QEGmVu7nbzBYXeScj1_5UBx7DOkiKp96JjDQg6edacTyEF93a28IVU-a9Dp-9tSo5PqlUJTrdPqKwqgmjJCy9T3dZmCuYoh3CeEAdrtMMyzcv9X8RUXDEDx0Vk8UJRpEdPNxfGYWHhh5_Jau-pO75c212wfBDcmucw-Hb6G7ZFoIg0m5sSK2Q6hlSSjsVI7TBWkRybIjZIBHt-OIAux4uZljJNRlyyVxSQiaNAhQ6ChvuclRiQWYtNZHEiz2pBd3pL9SkKX21-4FUHxjBIM1fiY0fki7N7eQWG4b3dja3TnjtE-b9_uQ8l8Q-XH_CYkW1hxpsuVApMwndqdLSmFnBP8UXOq7dF-w_CIizNSd-rQw1aYZToF8ZiddcGoFAt4tXtF_F0mllYdMLpPSGQoNgy2iYYqW1g8FH-p_YmhdxJ0qsMH-Oel0VAd-q0MAbsRsJ; Path=/; Domain=API.com; Max-Age=31536000; HttpOnly’), (‘x-tt-trace-tag’, ‘id=16;cdn-cache=miss;type=dyn’), (‘server-timing’, ‘cdn-cache; desc=MISS, edge; dur=1, origin; dur=360’), (‘x-origin-response-time’, ‘360,23.207.216.25’), (‘x-check-cacheable’, ‘NO’), (‘x-akamai-request-id’, ‘373e52db’)])
I am trying to extract the value tt-target-idc-sign=
and using it in next request, but am unable to get the value using my below code:
response = self.post_request(session, query_str, headers, body)
print(response.headers)
for line in response.headers:
print(line)
#if line[0] == 'set-cookie':
#if line[1].startswith('tt-target-idc-sign='):
#sign = line[1].split('=', 1)[1].split(';', 1)[0]
#print("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", sign)
With failed attempt. Printing "line" show me below:
server
content-type
content-length
content-encoding
bd-tt-error-code
vary
x-tt-logid
x-tt-store-idc
x-tt-store-region
x-tt-store-sec-uid
tt-idc-switch
access-control-expose-headers
server-timing
x-tt-trace-host
x-tt-trace-id
date
x-cache
set-cookie
x-tt-trace-tag
x-origin-response-time
x-check-cacheable
x-akamai-request-id
Without "tt-target-idc-sign=" !
So how to Extracting value: tt-target-idc-sign=
Thank you
2
Answers
You can’t see in line is because tt-target-idc-sign is located in set-cookie. You actually have extracted the value. Just delete the annotation you write below and you will see your target data.
response.headers
is of typeCaseInsensitiveDict
, so to get the value of set-cookie the code has to refer to it as to a dictionary item, like: