因此,我不得不修改您的代码才能运行。我在Ubuntu 14.04上使用Python 3.4.3。
#import urllib import urllib.parseimport urllib.request
我收到了类似的错误:
heyandy889@laptop:~/src/test$ python3 help.py Enter location: MIRetrieving http://maps.googleapis.com/maps/api/geopre/json?sensor=false&address=MIRetrieved 1405 charactersTraceback (most recent call last): File "help.py", line 18, in <module> js = json.loads(str(data)) File "/usr/lib/python3.4/json/__init__.py", line 318, in loads return _default_deprer.depre(s) File "/usr/lib/python3.4/json/deprer.py", line 343, in depre obj, end = self.raw_depre(s, idx=_w(s, 0).end()) File "/usr/lib/python3.4/json/deprer.py", line 361, in raw_depre raise ValueError(errmsg("Expecting value", s, err.value)) from NonevalueError: Expecting value: line 1 column 1 (char 0)
基本上,我们不是尝试解码有效的json字符串,而是尝试解码无效的json的Python“
None”值。尝试在以下示例代码中打补丁。首先运行一次,仔细检查最简单的json对象’{}’是否可以工作。然后,一个一个地尝试每个不同的“
possible_json_string”。
#...print ('Retrieved',len(data),'characters')#possible_json_string = str(data) #original errorpossible_json_string = '{}' #sanity check with simplest json#possible_json_string = data #why convert to string at all?#possible_json_string = data.depre('utf-8') #intentional conversionprint('possible_json_string')print(possible_json_string)js = json.loads(possible_json_string)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)