0
while url:
      post = session.post(login, data=payload)
      r = session.get(url)
      parsed = json.loads(r.text)
      # Retrieve json product data
      if parsed['links']['next'] is not 'null':
            url = 'https://testshop.example.com/admin/products' + str(parsed['links']['next'])
            time.sleep(2)
            for product in parsed['products']:
                parsed_result = product['id'] 
      else: 
           print('stop now!')
           break

SO I am using the code above to retrieve and print all the json data in my terminal. Everything is going fine until I retrieve the following error code at the end:

    raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value 

Does anybody know what the cause is of this and how I can fix it?

This is my JSON format if that matters:

products: [
{
article_code: "123",
barcode: "456",
brand_id: 2600822,
created_at: "2018-05-31T15:15:34+02:00",
data01: "",
data02: "",
data03: "",
delivery_date_id: null,
has_custom_fields: false,
has_discounts: false,
has_matrix: false,
hits: 0,
hs_code: null,
id: 72660113,
image_id: null,
is_visible: false,
price_excl: 33.0165,
price_incl: 39.95,
price_old_excl: 0,
price_old_incl: 0,
product_set_id: null,
product_type_id: null,
search_context: "123 456 789",
shop_id: 252449,
sku: "789",
supplier_id: 555236,
updated_at: "2018-05-31T15:15:34+02:00",
variants_count: 1,
visibility: "hidden",
weight: 0,
nl: {
content: "",
fulltitle: "Grid Lifter",
slug: "grid-lifter",
title: "Grid Lifter"
}
],

links: {
first: ".json",
last: ".json?page=70",
prev: null,
next: ".json?page=2",
count: 3497,
limit: 50,
pages: 70
}

I am using this to paginate through all the pages.

Traceback:

File "", line 1, in runfile('loginlightspeedshop.py', wdir='C:/Users/Solaiman/.spyder-py3/SCRIPTS/Lightspeed scripts')

File "sitecustomize.py", line 705, in runfile execfile(filename, namespace)

File "sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Solaiman/.spyder-py3/SCRIPTS/Lightspeed scripts/loginshop.py", line 33, in parsed = json.loads(r.text)

File "C:\Users\Solaiman\Anaconda3\lib\json__init__.py", line 354, in loads return _default_decoder.decode(s)

File "decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end())

File "decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value

2
  • Can you provide the actual traceback? Best guess is that r.text is None or an empty string on the last iteration through the loop. Commented Jun 26, 2018 at 15:06
  • @MatthewStory I have added a traceback Commented Jun 26, 2018 at 15:08

1 Answer 1

1

You are probably getting empty/not json response here:

r = session.get(url)

Try to print r.text before parsing it to detect problem cause. Or use try/except clause:

try:
    parsed = r.json()
except ValueError:
    print(r.text)
    break
Sign up to request clarification or add additional context in comments.

1 Comment

Good one thanks for your answer, I see the error now. I get a 404 error, really weird. Maybe I sent too much requests to the page.

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.