0

I have a scenario where I want to pass the data from a dict to a endpoint in a for loop.

here is what I have tried :

data3= [{'spcg': [{'a_id': 234, 'b_id': 1122, 'cls': [{'address': '{"fgt":"Cc","Ik":"01","IV_Y":"CP1","IID":"0054","IY":1,"SL":"https://ap.com","OC":""}', 'cl_id': 456103, 'type': 'SC', 'name': 'SFTPC', 'srt': 'sdp%', 'oner': 'ar'}], 'adata': False}], 'e_id': 1122}, {'spcg': [{'a_id': 456, 'b_id': 1111, 'cls': [{'address': '{"fgt":"Cc","Ik":"01","IV_Y":"CP1","IID":"0054","IY":1,"SL":"https://ap.com","OC":""}', 'cl_id': 4545673, 'type': 'SG', 'name': 'SMC', 'srt': 'sdfe', 'oner': 'agtr'}], 'adata': False}], 'e_id': 1111}]
for key in data3:
    temp=(key['spcg'])
    ab=requests.post('https://app/v1/end', headers =headers_active_spc, data=temp)
    print(temp)

Error I am receiveing :

ValueError: too many values to unpack (expected 2)

in

ab=requests.post('https://app/v1/end', headers =headers_active_spc, data=temp)

How can I pass all the spcg values ad body in POST request one by one as I tried in for loop.

5
  • 1
    Try data=json.dumps(payload) or json=temp (that'll take care of it) Commented Mar 5, 2020 at 8:45
  • @Sharad json=temp ? Commented Mar 5, 2020 at 8:48
  • Make it ab=requests.post('https://app/v1/end', headers =headers_active_spc, json=temp) instead Commented Mar 5, 2020 at 8:48
  • @Saharsh Doesnt works , same error Commented Mar 5, 2020 at 9:00
  • @John are you sure? I just tried it and it seems to be working fine for me. (Only errors are related to HTTP Connection since that URL is invalid my system). ValueError will only appear when you are trying to pass a dict into data parameter Commented Mar 5, 2020 at 9:43

1 Answer 1

1

try sending post request with JSON format data=json.dumps(temp)

where json can be imported as import json

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.