Python小白鸭2 发表于 2021-11-8 19:49:40

31讲 泡菜

请输入城市:成都
Traceback (most recent call last):
File "E:\学习资料\python实例\031永久存储:腌制一缸美味的泡菜(课件+源代码)\天气查询\天气查询(改).py", line 12, in <module>
    weatherJSON = json.JSONDecoder().decode(weatherHTML)
File "C:\Program Files\Python39\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\Python39\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

我跟鱼C一样 改了之后 为什么又有错误 也没搞懂哪里有错

以下是代码:

import urllib.request
import json
import pickle

pickle_file = open('city_data.pkl','rb')
city = pickle.load(pickle_file)

password=input('请输入城市:')
name1=city
File1 =urllib.request.urlopen('http://m.weather.com.cn/data/'+name1+'.html')
weatherHTML= File1.read().decode('utf-8')
weatherJSON = json.JSONDecoder().decode(weatherHTML)
weatherInfo = weatherJSON['weatherinfo']
print ( '城市:', weatherInfo['city'])
print ('时间:', weatherInfo['date_y'])
print ( '24小时天气:')
print ('温度:', weatherInfo['temp1'])
print ('天气:', weatherInfo['weather1'])
print ('风速:', weatherInfo['wind1'])
print ('紫外线:', weatherInfo['index_uv'])
print ('穿衣指数:', weatherInfo['index_d'])
print ('48小时天气:')
print ('温度:', weatherInfo['temp2'])
print ('天气:', weatherInfo['weather2'])
print ('风速:', weatherInfo['wind2'])
print ('紫外线:', weatherInfo['index48_uv'])
print ('穿衣指数:', weatherInfo['index48_d'])
print ('72小时天气:')
print ('温度:', weatherInfo['temp3'])
print ('天气:', weatherInfo['weather3'])
print ('风速:', weatherInfo['wind3'])
input ('按任意键退出:')

我之前的pkl文件与天气脚本的文件不在同一个文件夹,后面我改过去以后 发现还是报错

求解答!!!

Python小白鸭2 发表于 2021-11-8 19:51:03

是我的一些东西没有安装上吗
页: [1]
查看完整版本: 31讲 泡菜