Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108440

Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!ecngs!testfeeder.ecngs.de!81.171.118.63.MISMATCH!peer03.fr7!news.highwinds-media.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)
Date Mon, 9 May 2016 19:07:38 -0400
Lines 37
Message-ID <mailman.551.1462835277.32212.python-list@python.org> (permalink)
References <137a2593-c307-405f-8f23-3959099ff16f@googlegroups.com> <ngr57s$eas$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de W6C4/SCpsJUrntqQooY9nwBMjomPtiVSqmA2/Raeeciw==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'debug': 0.04; 'error:': 0.05; 'newbie': 0.05; 'python3': 0.05; "'a'": 0.07; 'column': 0.07; 'valueerror:': 0.07; '(char': 0.09; 'expected.': 0.09; 'obj,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.11; 'question.': 0.13; 'skip:f 30': 0.15; 'decode': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject: \n (': 0.16; 'value",': 0.16; 'value:': 0.16; 'wrote:': 0.16; 'debugging': 0.18; 'variable': 0.18; 'versions': 0.20; '"",': 0.22; 'exec': 0.22; "skip:' 40": 0.22; 'programming': 0.22; 'this:': 0.23; 'second': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:_ 20': 0.26; 'skip:( 20': 0.28; 'looks': 0.29; 'loads': 0.29; "skip:' 50": 0.29; 'raise': 0.29; 'skip:b 40': 0.29; 'print': 0.30; 'classes': 0.30; 'posting': 0.32; 'statement': 0.32; 'getting': 0.33; 'traceback': 0.33; 'file': 0.34; 'done': 0.35; 'community': 0.36; 'should': 0.36; 'basic': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'skip:v 20': 0.38; 'files': 0.38; 'hi,': 0.38; 'end': 0.39; 'means': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'questions': 0.40; 'email addr:gmail.com': 0.62; 'received:96': 0.63; 'better.': 0.66; 'numerous': 0.66; 'teach': 0.70; 'subject:value': 0.84; 'edition': 0.86; 'received:fios.verizon.net': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pool-96-227-207-81.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0
In-Reply-To <137a2593-c307-405f-8f23-3959099ff16f@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <ngr57s$eas$1@ger.gmane.org>
X-Mailman-Original-References <137a2593-c307-405f-8f23-3959099ff16f@googlegroups.com>
X-Received-Bytes 5046
X-Received-Body-CRC 1163132274
Xref csiph.com comp.lang.python:108440

Show key headers only | View raw


On 5/9/2016 3:56 PM, zljubisic@gmail.com wrote:
> Hi,
>
> in python3 my variable looks like this:
>
> a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
> str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''
>
> If I execute the following command I get the error:
>
>>>> json.loads(str(a))
> Traceback (most recent call last):
>   File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
>     exec(exp, global_vars, local_vars)
>   File "<input>", line 1, in <module>
>   File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in loads
>     return _default_decoder.decode(s)
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in decode
>     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in raw_decode
>     raise ValueError(errmsg("Expecting value", s, err.value)) from None
> ValueError: Expecting value: line 1 column 1 (char 0)
>
> Why I am getting this error?
> If I set variable a to the '{"uuid":"5730e8666ffa02.34177329","error":""}' everything works as expected.

This means that the two versions of 'a' are not the same.  So what you 
should have done to debug is print the second to see what you actually 
passed to json.

Editorial: Programming classes should teach basic debugging better. I 
have seen numerous newbie Stackoverflow questions where the person 
should have started with adding a print statement before posting a question.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) zljubisic@gmail.com - 2016-05-09 12:56 -0700
  Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) Peter Otten <__peter__@web.de> - 2016-05-09 22:17 +0200
  Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) MRAB <python@mrabarnett.plus.com> - 2016-05-09 21:21 +0100
  Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-05-09 21:41 +0100
  Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) Terry Reedy <tjreedy@udel.edu> - 2016-05-09 19:07 -0400
    Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) Steven D'Aprano <steve@pearwood.info> - 2016-05-10 12:13 +1000
      Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) Rustom Mody <rustompmody@gmail.com> - 2016-05-09 21:22 -0700
        Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0) zljubisic@gmail.com - 2016-05-10 12:27 -0700

csiph-web