Python 2.7 Requests GET with header

1k views Asked by At

I'm trying to send a header with a requests.get:

import requests


url = 'http://qp-nachorat2000:8018/icws/' + sessionID + '/status/user-statuses/Administrator' 
header = {'ININ-ICWS-CSRF-Token': csrfToken} 
pcRequest = requests.get(url, headers=header)

This results in a 400 response:

{u'errorCode': 2, 
 u'message': u'A session CSRF token is needed for this request, but none was provided.', 
 u'errorId': u'error.request.accessDenied.csrfToken.missing'}

The same GET works perfectly fine in Postman:

asdfd

What am I missing? Any help would be appreciated.

1

There are 1 answers

0
ky922 On

This question is really old, but here's your answer for anyone looking.

When you make your original connection like this:

r = requests.post(url, json=jsonData, headers=header, verify=False)
print(r.status_code)
j = json.loads(r.text)

you will need to pass data from that json data that is returned into the header of the get request:

   header = {
            "Accept-Language": "en-us",
            'Token': j['Token'],
            'Content-Type': 'application/json',
            'Cookie': cookievalue,
            }

Essentially just take the json data that is returned from the original connection attempt, and using the ['Token'] key, pass that as the token in the header of the GET.