import urllib.request
#不能import urllib,不知道为啥
import json


params = urllib.parse.urlencode({"city": "北京","key": "xxxxxxxxxxxxxxxxxxxxx"})
#将参数转化为url格式
data_api = params.encode()
#将参数转化为二进制
req = urllib.request.Request('http://apis.juhe.cn/simpleWeather/query', data_api)
#将参数与url合并
response = urllib.request.urlopen(req)
#连接url
content = response.read()
#读取url
result = json.loads(content.decode('utf-8'))
#json格式
print(result['result']['realtime']['temperature'])