|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- Traceback (most recent call last):
- File "C:\Users\shuoguo-win10\Desktop\rz\天气查询2.py", line 9, in <module>
- File1 =urllib.request.urlopen('http://m.weather.com.cn/data/'+name1+'.html')#打开url
- File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 222, in urlopen
- return opener.open(url, data, timeout)
- File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 531, in open
- response = meth(req, response)
- File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 640, in http_response
- response = self.parent.error(
- File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 569, in error
- return self._call_chain(*args)
- File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 502, in _call_chain
- result = func(*args)
- File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 649, in http_error_default
- raise HTTPError(req.full_url, code, msg, hdrs, fp)
- urllib.error.HTTPError: HTTP Error 403: Forbidden
- >>>
复制代码
这是报错内容
- import urllib.request
- import json
- import pickle
- pickle_file=open('city_data.pkl','rb')
- city=pickle.load(pickle_file)
- password=input('请输入城市:')
- name1=city[password]
- File1 =urllib.request.urlopen('http://m.weather.com.cn/data/'+name1+'.html')#打开url
- weatherHTML= File1.read().decode('utf-8')#读入打开的url
- weatherJSON = json.JSONDecoder().decode(weatherHTML)#创建json
- 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 ('按任意键退出:')
复制代码
这是代码,这个文件是在第31课腌制一缸美味的泡菜中跟甲鱼老湿敲的。。。
这里面导入了一个pkl文件,导入没有问题,文件应该就不用发了吧.... |
|