天气接口,加入个超时.现在好像只成功了一次,感觉是被限制了调用情况
This commit is contained in:
@@ -522,13 +522,13 @@ class WeatherPlugin(MessagePluginInterface):
|
|||||||
# 获取实时天气
|
# 获取实时天气
|
||||||
conn = aiohttp.TCPConnector(ssl=False)
|
conn = aiohttp.TCPConnector(ssl=False)
|
||||||
now_url = f'{self.api_domain}/v7/weather/now?key={self.api_key}&location={city_id}'
|
now_url = f'{self.api_domain}/v7/weather/now?key={self.api_key}&location={city_id}'
|
||||||
async with aiohttp.request('GET', now_url, connector=conn) as resp:
|
async with aiohttp.request('GET', now_url, connector=conn,timeout=20) as resp:
|
||||||
now_json = await resp.json()
|
now_json = await resp.json()
|
||||||
|
|
||||||
# 获取预报
|
# 获取预报
|
||||||
conn = aiohttp.TCPConnector(ssl=False)
|
conn = aiohttp.TCPConnector(ssl=False)
|
||||||
daily_url = f'{self.api_domain}/v7/weather/7d?key={self.api_key}&location={city_id}'
|
daily_url = f'{self.api_domain}/v7/weather/7d?key={self.api_key}&location={city_id}'
|
||||||
async with aiohttp.request('GET', daily_url, connector=conn) as resp:
|
async with aiohttp.request('GET', daily_url, connector=conn,timeout=20) as resp:
|
||||||
daily_json = await resp.json()
|
daily_json = await resp.json()
|
||||||
|
|
||||||
if now_json.get('code') != '200' or daily_json.get('code') != '200':
|
if now_json.get('code') != '200' or daily_json.get('code') != '200':
|
||||||
|
|||||||
Reference in New Issue
Block a user