0

I am using a python rest api and want to fetch data from an api which gives me json response with a padding(jsonp request). I have seen few examples where javascript(jquery and angularjs) need to add a callback function for getting json. How to do the same with python?

1 Answer 1

4

You don't need to, the padding is only needed in browser/JavaScript context to bypass certain security constraints. For Python usage just take the raw response, remove the padding and parse the remaining data accordingly.

from json import loads

a = 'paddingFunction({"a":1,"b":2,"c":3,"d":4,"e":5})'
startidx = a.find('(')
endidx = a.rfind(')')

print loads(a[startidx + 1:endidx])
>>> {u'a': 1, u'c': 3, u'b': 2, u'e': 5, u'd': 4}
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.