-1

I have sent a JSON request. I am getting a 200 response which means that the sent request was accepted and that there is a response. I am trying to view the full response that was sent back from the request. I have tried 3-4 different ways of viewing the response, but no matter what i try, i cant figure out how to view the full response... Can anyone help me figure out how to see the information..

Request -

def createUserSynapse():
    url = 'http://uat-api.synapsefi.com'
    headers = {
        'X-SP-GATEWAY' : 'client_id_asdfeavea561va9685e1gre5ara|client_secret_4651av5sa1edgvawegv1a6we1v5a6s51gv',
        'X-SP-USER-IP' : '127.0.0.1',
        'X-SP-USER' : 'ge85a41v8e16v1a618gea164g65',
        'Contant-Type' : 'application/json',
    }
    payload = {
        "logins":[
            {
                "email":"test@test.com",
            }
        ],
        "phone_numbers":[
            "123.456.7890",
            "test@test.com",
        ],
        "legal_names":[
            "Test name",
        ],
        "extras":{
            "supp_id":"asdfe515641e56wg",
            "cip_tag":12,
            "is_business":False,
        }
    }
    print(url)
    print(headers)
    print(payload)
    call = requests.post(url, data=json.dumps(payload), headers=headers)
    print(call)
    return call

The response that i am getting from the request (I have a line to print the request)...

<Response [200]>
Oluwafemi Sule
  • 27,776
  • 1
  • 40
  • 64
Omar Jandali
  • 656
  • 1
  • 11
  • 36

1 Answers1

0

Try changing call to

call.text

For JSON try

json.loads(call.text)

To print

print(json.loads(call.text))
M3RS
  • 4,254
  • 1
  • 24
  • 40
  • 1
    `call.json()` in a proper _try/except_ block would be nicer. see the [doc](http://docs.python-requests.org/en/master/user/quickstart/#response-content) – ohannes Aug 30 '17 at 21:50
  • i got an error `AttributeError at /signup 'str' object has no attribute 'read'` when i tried to run the following code... `print(json.load(call.text))` – Omar Jandali Aug 30 '17 at 21:53
  • that part of the code is not shown above, as far as I can tell, so not sure what happened – M3RS Aug 30 '17 at 21:55
  • 1
    @OmarJandali it is not `json.load` but `json.loads`, notice the **s** at the end. – ohannes Aug 30 '17 at 21:57
  • I chaged `load` to `loads` and now this is coming up `Expecting value: line 1 column 1 (char 0)` – Omar Jandali Aug 30 '17 at 22:23
  • are you also doing `return json.loads(call.text)`? this might also help https://stackoverflow.com/questions/16573332/jsondecodeerror-expecting-value-line-1-column-1-char-0 – M3RS Aug 30 '17 at 22:28
  • I have tried everything and it is still not printing the json data. so i have to create a template for it to display in an html file... – Omar Jandali Aug 30 '17 at 23:54