1

This is my code below:

from urllib.request import urlopen
import json
import requests

url = 'https://production-us-adidasgroup.demandware.net/s/adidas-US/dw/shop/v15_6/products/(CQ1862)?client_id=392f521c-cf82-4c24-8ee4-97b4bfe926c5&expand=availability,variations,prices&callback=jQuery311046436681352330944_1508679685699&_=1508679685720.json'

s = requests.session()

res = s.get(url)
json_dict = res.json()

qty = json_dict['inventory']['ats']

print(qty)

I am trying to parse the 'ats' from the url, but keep running into error:

simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I think it's because in the URL the first line doesn't have value. Is there any way to skip this? I know I'm not using some of the modules I have imported.

1 Answer 1

1

The problem is that you are receiving a JSONP response which includes a function name. If you curl that URL you'll see the response starts with /**/jQuery311046436681352330944_1508679685699({. This is the same value you can see in the URL: callback=jQuery311046436681352330944_1508679685699

To get rid of this, drop the callback parameter from the URL. Use https://production-us-adidasgroup.demandware.net/s/adidas-US/dw/shop/v15_6/products/(CQ1862)?client_id=392f521c-cf82-4c24-8ee4-97b4bfe926c5&expand=availability,variations,prices&_=1508679685720.json instead.

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

2 Comments

i still get the same jsonDecodeError, can you run it?
Odd… I can get it with curl, but not using requests library

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.