Closed KafCoppelia closed 2 years ago
已修改,修改后,返回的报错同上,应该是Location ID获取不了,但是单独在浏览器内可以返回正确的location信息,理解不能。
另外,在bot根目录下,已设置.env.prod内QWEATHER_APIKEY = "我的KEY"
哦! 你输入的命令应该要是 天气北京
或 北京天气
....(:з」∠)
404
代表 查询的数据或地区不存在。
啊嗯,看readme还以为有中间的“+”号QAQ
私聊机器人,输入“天气北京”:
12-28 16:02:50 [INFO] nonebot | Event will be handled by <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False>
12-28 16:02:51 [INFO] nonebot | Matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> running complete
12-28 16:02:51 [ERROR] nonebot | Running matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> failed.
Traceback (most recent call last):
File "/root/anaconda3/envs/nonebot_v2/bin/nb", line 8, in
File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/message.py", line 156, in _run_matcher await matcher.run(bot, event, state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/matcher.py", line 597, in run await handler(self, bot, event, self.state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/handler.py", line 64, in call await self.func( File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_pluginheweather/init.py", line 36, in data = await get_City_Weather(city) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_plugin_heweather/get_weather.py", line 52, in get_City_Weather daily = daily_info["daily"] KeyError: 'daily'
输入“北京天气”:
12-28 16:02:57 [INFO] nonebot | Event will be handled by <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False>
12-28 16:02:57 [INFO] nonebot | Matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> running complete
12-28 16:02:57 [ERROR] nonebot | Running matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> failed.
Traceback (most recent call last):
File "/root/anaconda3/envs/nonebot_v2/bin/nb", line 8, in
File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/message.py", line 156, in _run_matcher await matcher.run(bot, event, state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/matcher.py", line 597, in run await handler(self, bot, event, self.state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/handler.py", line 64, in call await self.func( File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_pluginheweather/init.py", line 36, in data = await get_City_Weather(city) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_plugin_heweather/get_weather.py", line 52, in get_City_Weather daily = daily_info["daily"] KeyError: 'daily' 我哭死,我感觉JSON解析没问题诶
怪!按道理商业版和开发的返回的格式应该是一样的!
你试试在
https://github.com/kexue-z/nonebot-plugin-heweather/blob/fe4a0e7ff0470ef000279aa386f7acc18882b6e9/nonebot_plugin_heweather/get_weather.py#L51
后添加 logger.error(daily_info)
看看返回数据是怎样的
logger.error(daily_info)
后再次使用商业版API测试(API与其对应链接确保正确),返回报错:
`12-29 00:15:42 [INFO] nonebot | Event will be handled by <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False>
12-29 00:15:42 [INFO] nonebot | Matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> running complete
12-29 00:15:42 [ERROR] nonebot | Running matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> failed.
Traceback (most recent call last):
File "/root/anaconda3/envs/nonebot_v2/bin/nb", line 8, in File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/message.py", line 156, in _run_matcher await matcher.run(bot, event, state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/matcher.py", line 597, in run await handler(self, bot, event, self.state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/handler.py", line 64, in call await self.func( File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_pluginheweather/init.py", line 36, in data = await get_City_Weather(city) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_plugin_heweather/get_weather.py", line 52, in get_City_Weather daily = daily_info["daily"] KeyError: 'daily'` 我不知道返回的数据在哪里,查看了error.log内的日志也是上面这些。
那。。。还是用开发版吧( 或者可以借用一下apikey给我测试一下)目前正在重写用html渲染的版本
OK,已新开一个商业版API,确认有效,一周后我会删除:[---]。 主要是我自己的另外一个项目也使用WIFI芯片访问和风天气,通过API获取数据,但是用商业版的KEY在获取location ID的时候不行,而浏览器始终可以(无论商业还是开发),所以有些在意这个问题。
已添加 https://github.com/kexue-z/nonebot-plugin-heweather/commit/85031fc3966194894d3cee195c0c2994f1159da8
使用商业版需在env中添加QWEATHER_COMMERCIAL=true
OK,可以在README里添加商业版设置的提示
你慢了 我已经加了 😁
又试了一下0.4.0,使用商业版,仍报错
……………… daily = daily_info["daily"] KeyError: 'daily'
🤔
试试用最新的commit 并使用debug模式打印输出
这是用你给我提供的apikey 里面确认是使用商业版的
🤔从输入“北京天气”到报错全过程:
12-30 15:20:58 [DEBUG] nonebot | Running PreProcessors...
12-30 15:20:58 [DEBUG] nonebot | CQHTTP | Calling API get_group_info
12-30 15:20:58 [DEBUG] nonebot | Running CalledAPI hooks...
12-30 15:20:58 [DEBUG] nonebot | Checking for matchers in priority 1...
12-30 15:20:58 [INFO] nonebot | Event will be handled by <Matcher from unknown, type=message, priority=1, temp=False>
12-30 15:20:58 [DEBUG] nonebot | Running matcher <Matcher from unknown, type=message, priority=1, temp=False>
12-30 15:20:58 [DEBUG] nonebot | Running handler <Handler _tietie_superuser(bot: <class 'nonebot.adapters.cqhttp.bot.Bot'>, event: <class 'nonebot.adapters.cqhttp.event.MessageEvent'>, state: None, matcher: None)>
12-30 15:20:58 [DEBUG] nonebot | CQHTTP | Calling API send_msg
12-30 15:20:58 [INFO] nonebot | Event will be handled by <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False>
12-30 15:20:58 [DEBUG] nonebot | Running matcher <Matcher from nonebot_pluginheweather, type=message, priority=1, temp=False>
12-30 15:20:58 [DEBUG] nonebot | Running handler <Handler (bot: <class 'nonebot.adapters.cqhttp.bot.Bot'>, event: <class 'nonebot.adapters.cqhttp.event.MessageEvent'>, state: None, matcher: None)>
12-30 15:20:58 [DEBUG] nonebot_plugin_heweather | {'code': '200', 'location': [{'name': '北京', 'id': '101010100', 'lat': '39.90498', 'lon': '116.40528', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '10', 'fxLink': 'http://hfx.link/2ax1'}, {'name': '海淀', 'id': '101010200', 'lat': '39.95607', 'lon': '116.31031', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '15', 'fxLink': 'http://hfx.link/2ay1'}, {'name': '朝阳', 'id': '101010300', 'lat': '39.92149', 'lon': '116.48641', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '15', 'fxLink': 'http://hfx.link/2az1'}, {'name': '昌平', 'id': '101010700', 'lat': '40.21808', 'lon': '116.23590', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '23', 'fxLink': 'http://hfx.link/2b31'}, {'name': '房山', 'id': '101011200', 'lat': '39.73553', 'lon': '116.13916', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '23', 'fxLink': 'http://hfx.link/2b81'}, {'name': '通州', 'id': '101010600', 'lat': '39.90248', 'lon': '116.65860', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '23', 'fxLink': 'http://hfx.link/2b21'}, {'name': '丰台', 'id': '101010900', 'lat': '39.86364', 'lon': '116.28696', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '25', 'fxLink': 'http://hfx.link/2b51'}, {'name': '大兴', 'id': '101011100', 'lat': '39.72890', 'lon': '116.33803', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '25', 'fxLink': 'http://hfx.link/2b71'}, {'name': '延庆', 'id': '101010800', 'lat': '40.46532', 'lon': '115.98500', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '33', 'fxLink': 'http://hfx.link/2b41'}, {'name': '平谷', 'id': '101011500', 'lat': '40.14478', 'lon': '117.11233', 'adm2': '北京', 'adm1': '北京市', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '33', 'fxLink': 'http://hfx.link/2bb1'}], 'refer': {'sources': ['QWeather'], 'license': ['commercial license']}}
12-30 15:20:58 [INFO] nonebot | Matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> running complete
12-30 15:20:58 [ERROR] nonebot | Running matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> failed.
Traceback (most recent call last):
File "
File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/message.py", line 156, in _run_matcher await matcher.run(bot, event, state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/matcher.py", line 597, in run await handler(self, bot, event, self.state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/handler.py", line 64, in call await self.func( File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_pluginheweather/init.py", line 36, in data = await get_City_Weather(city) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_plugin_heweather/get_weather.py", line 52, in get_City_Weather daily = daily_info["daily"] KeyError: 'daily' 用的同样是你现在用的商业版API
你可能是之前的版本。 你可以直接把源码下载放到你的插件目录中运行
啊嗯我就是将原来的通过nb plugin install下载的包给uninstall后git clone 最新的至plugins下,通过nonebot.install_plugin()安装的,而不是加载至toml里
???我不理解
直接把它丢进bot文件夹然后nonebot.load_plugins("plugins")
就行了
啊嗯我表达的就是这个意思,现在pc不在我身边,我就是这个方式加载最新0.4.0版本的
可是你这报错的路径并不在bot的路径吧?
File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_pluginheweather/init.py", line 36, in data = await get_City_Weather(city) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_plugin_heweather/get_weather.py", line 52, in get_City_Weather daily = daily_info["daily"] KeyError: 'daily'
文件在这里
/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot_plugin_heweather/get_weather.py
🤔有道理,我再研究一下
重新git clone 最新的repo,新的html渲染的图片很好看。商业版API反复验证了几次完全OK,但是用开发版API反而出现问题😥报错如下:
12-31 00:09:08 [SUCCESS] nonebot | CQHTTP 3375089585 | [message.private.friend]: Message 1496492867 from 740677208 "长沙天气"
12-31 00:09:08 [DEBUG] nonebot | Running PreProcessors...
12-31 00:09:08 [DEBUG] nonebot | Checking for matchers in priority 1...
12-31 00:09:08 [INFO] nonebot | Event will be handled by <Matcher from unknown, type=message, priority=1, temp=False>
12-31 00:09:08 [DEBUG] nonebot | Running matcher <Matcher from unknown, type=message, priority=1, temp=False>
12-31 00:09:08 [DEBUG] nonebot | Running handler <Handler _tietie_superuser(bot: <class 'nonebot.adapters.cqhttp.bot.Bot'>, event: <class 'nonebot.adapters.cqhttp.event.MessageEvent'>, state: None, matcher: None)>
12-31 00:09:08 [DEBUG] nonebot | CQHTTP | Calling API send_msg
12-31 00:09:08 [INFO] nonebot | Event will be handled by <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False>
12-31 00:09:08 [DEBUG] nonebot | Running matcher <Matcher from nonebot_pluginheweather, type=message, priority=1, temp=False>
12-31 00:09:08 [DEBUG] nonebot | Running handler <Handler (bot: <class 'nonebot.adapters.cqhttp.bot.Bot'>, event: <class 'nonebot.adapters.cqhttp.event.MessageEvent'>, state: None, matcher: None)>
12-31 00:09:08 [DEBUG] nonebot_plugin_heweather | {'code': '200', 'location': [{'name': '长沙', 'id': '101250101', 'lat': '28.19409', 'lon': '112.98227', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '11', 'fxLink': 'http://hfx.link/3ef1'}, {'name': '长沙县', 'id': '101250106', 'lat': '28.23788', 'lon': '113.08010', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '25', 'fxLink': 'http://hfx.link/1tjm1'}, {'name': '宁乡', 'id': '101250102', 'lat': '28.25392', 'lon': '112.55318', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '23', 'fxLink': 'http://hfx.link/3eg1'}, {'name': '浏阳', 'id': '101250103', 'lat': '28.14111', 'lon': '113.63330', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '23', 'fxLink': 'http://hfx.link/3eh1'}, {'name': '天心', 'id': '101250108', 'lat': '28.19237', 'lon': '112.97306', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '35', 'fxLink': 'http://hfx.link/1tyf1'}, {'name': '岳麓', 'id': '101250109', 'lat': '28.21304', 'lon': '112.91159', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '35', 'fxLink': 'http://hfx.link/1tyg1'}, {'name': '芙蓉', 'id': '101250107', 'lat': '28.19310', 'lon': '112.98809', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '35', 'fxLink': 'http://hfx.link/1tye1'}, {'name': '望城', 'id': '101250105', 'lat': '28.34745', 'lon': '112.81955', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '35', 'fxLink': 'http://hfx.link/3ej1'}, {'name': '开福', 'id': '101250110', 'lat': '28.20133', 'lon': '112.98552', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '35', 'fxLink': 'http://hfx.link/1tyh1'}, {'name': '雨花', 'id': '101250111', 'lat': '28.10993', 'lon': '113.01633', 'adm2': '长沙', 'adm1': '湖南省', 'country': '中国', 'tz': 'Asia/Shanghai', 'utcOffset': '+08:00', 'isDst': '0', 'type': 'city', 'rank': '35', 'fxLink': 'http://hfx.link/1tyi1'}], 'refer': {'sources': ['QWeather'], 'license': ['commercial license']}}
12-31 00:09:08 [DEBUG] nonebot_plugin_heweather | {'code': '403'}
12-31 00:09:08 [INFO] nonebot | Matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> running complete
12-31 00:09:08 [ERROR] nonebot | Running matcher <Matcher from nonebot_plugin_heweather, type=message, priority=1, temp=False> failed.
Traceback (most recent call last):
File "
File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/message.py", line 156, in _run_matcher await matcher.run(bot, event, state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/matcher.py", line 597, in run await handler(self, bot, event, self.state) File "/root/anaconda3/envs/nonebot_v2/lib/python3.9/site-packages/nonebot/handler.py", line 64, in call await self.func( File "/root/NONEBOT/AQUABOT/src/plugins/nonebot_pluginheweather/init.py", line 27, in data = await get_City_Weather(city) File "/root/NONEBOT/AQUABOT/src/plugins/nonebot_plugin_heweather/get_weather.py", line 64, in get_City_Weather daily = daily_info["daily"] KeyError: 'daily'
理解不能QAQ
有没有一种可能。。。你用的商业版的APIKEY去用开发版
12-31 00:09:08 [DEBUG] nonebot_plugin_heweather | {'code': '403'}
都报403了...
403 | 无访问权限,可能是绑定的PackageName、BundleID、域名IP地址不一致,或者是需要额外付费的数据。
怪!已设置QWEATHER_COMMERCIAL=false,API确认是开发版😫报错同上
那就不填 空着
怪!已设置QWEATHER_COMMERCIAL=false,API确认是开发版报错同上
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you modified the open/close state.Message ID: @.***>
不填t/f或者完全不写这一项错误还是相同,是不是“v7版本API默认采用gzip压缩“(来源官网提示)”的原因🤔
我测试过了 env 里只填 apikey 没有商业版的设置 如
ENVIRONMENT=pord
QWEATHER_APIKEY=abcabc
COMMAND_START=["/", ""]
能不能好好看log(
开发版
QWEATHER_APIKEY = [开发版KEY]
QWEATHER_COMMERCIAL =
或
QWEATHER_APIKEY = [开发版KEY]
都行
商业版
QWEATHER_APIKEY = [商业版KEY]
QWEATHER_COMMERCIAL = 1
1
的位置只要有东西都会判断为商业版
具体看log 都有写 确认你的key版本和配置是否相同
还有问题请发送带有nonebot_plugin_heweather
的log
你再试试最新的commit 应该会包括api错误情况下的
坏了,是我的开发版API无法访问7天天气预报了,我正在咨询和风天气那边。
和风天气给我的反馈是让我把和风的账户升级成个人开发者,升级后我用商用或开发版api key均OK🎈
获取信息失败,输入命令
/天气+北京
,返回错误信息12-25 08:53:56 [ERROR] nonebot_plugin_heweather | 错误: 404 请参考 https://dev.qweather.com/docs/start/status-code/
,初步判断为获取location ID失败,仅修改了源码中获取天气的api,从开发版改为个人的商业版。url_weather_api = "https://api.qweather.com/v7/weather/" url_geoapi = "https://geoapi.qweather.com/v2/city/"
个人使用的API确认有效。