Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/The raise jsondecodeerror("expecting value", s, err.value) from none error: What should you do?
Next
Answered
Daniel Smith
  • 21
Daniel Smith
Asked: May 18, 20222022-05-18T17:32:40+00:00 2022-05-18T17:32:40+00:00In: python

The raise jsondecodeerror(“expecting value”, s, err.value) from none error: What should you do?

  • 21

. Advertisement .

..3..

. Advertisement .

..4..

I am working on python, but I found the following warning message:

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

Is there any way to stabilize the issue “raise jsondecodeerror(“expecting value”, s, err.value) from none”? I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me? Please find the beginning command below:

import urllib
 import json
 
 serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json?'
 
 while True:
  address = input('Enter location: ')
  if len(address) < 1 : break
 
  url = serviceurl + urllib.parse.urlencode({'sensor':'false',
  'address': address})
  print ('Retrieving', url)
  uh = urllib.request.urlopen(url)
  data = uh.read()
  print ('Retrieved',len(data),'characters')
 
  js = json.loads(str(data))
jsondecodeerror
  • 2 2 Answers
  • 98 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-17T03:43:39+00:00Added an answer on June 17, 2022 at 3:43 am

    The cause: The “data” is of type bytes, so you must decode it into a string before using json.loads to transform it into a json object in order to avoid the error.

    Solution: You should decode the Python ‘None’ value, which is not acceptable json, rather than attempting to decode the valid json string. Try patching in the example code below. Run it once first to confirm that the simplest JSON object ‘{}’ will function. Next, try each ‘possible json string’ individually.

    #...
    print ('Retrieved',len(data),'characters')
    
    #possible_json_string = str(data) #original error
    possible_json_string = '{}' #sanity check with simplest json
    #possible_json_string = data #why convert to string at all?
    #possible_json_string = data.decode('utf-8') #intentional conversion
    
    print('possible_json_string')
    print(possible_json_string)
    js = json.loads(possible_json_string)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Nathan Vallet
    2022-05-25T20:40:26+00:00Added an answer on May 25, 2022 at 8:40 pm

    This error occurs because “data” is a type bytes. You will need to decode it to a string, before you use json.loads to convert it to a json objects. This will solve the problem.

    uh = urllib.request.urlopen(url)
    data = uh.read()
    print ('Retrieved',len(data),'characters')
    
    js = json.loads(data.decode("utf-8"))

    Additionally, str(data), in the code that you share with Python 2.x will work but not in Python 3.x. This is because str() does not convert bytes into strings in Python 3.x.

    • 11
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.