JSONDecodeError: Expecting value: line 1 column 1 (char 0)"
JSONDecodeError: Expecting value: line 1 column 1 (char 0)"
这是代码..
address_input = input("Enter location: ")
params = {"sensor": "false", "address": address_input}
serviceurl = "http://py4e-data.dr-chuck.net/json?"
url = serviceurl + urllib.parse.urlencode(params)
print("Retrieving ", url)
data = urllib.request.urlopen(url).read().decode('utf-8')
print('Retrieved', len(data), 'characters')
json_obj = json.loads(data)
place_id = json_obj["results"][0]["place_id"]
print("Place id", place_id)
这是我遇到的错误
here is the second image
要求:
- urllib
pip install urllib
- 请求
pip install requests
代码
import json
import urllib
import requests
address_input = input("Enter location: ")
params = {"sensor": "false", "address": address_input, "key": 42}
serviceurl = "http://py4e-data.dr-chuck.net/json?"
url = serviceurl + urllib.parse.urlencode(params)
print("Retrieving ", url)
resp = requests.get(url)
print('Retrieved', len(resp.content), 'characters')
json_obj = json.loads(resp.content)
place_id = json_obj["results"][0]["place_id"]
print("Place id", place_id)
输出
Enter location: UK
Retrieving http://py4e-data.dr-chuck.net/json?sensor=false&address=UK&key=42
Retrieved 1196 characters
Place id ChIJqZHHQhE7WgIReiWIMkOg-MQ
这是代码..
address_input = input("Enter location: ")
params = {"sensor": "false", "address": address_input}
serviceurl = "http://py4e-data.dr-chuck.net/json?"
url = serviceurl + urllib.parse.urlencode(params)
print("Retrieving ", url)
data = urllib.request.urlopen(url).read().decode('utf-8')
print('Retrieved', len(data), 'characters')
json_obj = json.loads(data)
place_id = json_obj["results"][0]["place_id"]
print("Place id", place_id)
这是我遇到的错误
here is the second image
要求:
- urllib
pip install urllib
- 请求
pip install requests
代码
import json
import urllib
import requests
address_input = input("Enter location: ")
params = {"sensor": "false", "address": address_input, "key": 42}
serviceurl = "http://py4e-data.dr-chuck.net/json?"
url = serviceurl + urllib.parse.urlencode(params)
print("Retrieving ", url)
resp = requests.get(url)
print('Retrieved', len(resp.content), 'characters')
json_obj = json.loads(resp.content)
place_id = json_obj["results"][0]["place_id"]
print("Place id", place_id)
输出
Enter location: UK
Retrieving http://py4e-data.dr-chuck.net/json?sensor=false&address=UK&key=42
Retrieved 1196 characters
Place id ChIJqZHHQhE7WgIReiWIMkOg-MQ