Добрый ночи, пытаюсь запустить погодного бота для телеграм, выдает ошибки, в чем проблема?
C:\Users\user\PycharmProjects\pythonProject\main.py:23: DeprecationWarning: There is no current event loop
loop = asyncio.get_event_loop()
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 24, in
loop.run_until_complete(getweather())
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
return future.result()
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 9, in getweather
weather = await client.find("New York")
File "C:\Users\user\PycharmProjects\pythonProject\venv\lib\site-packages\python_weather\client.py", line 36, in find
return await self.http.request(location)
File "C:\Users\user\PycharmProjects\pythonProject\venv\lib\site-packages\python_weather\rest.py", line 19, in request
parsed = parse(await resp.text())
File "C:\Users\user\PycharmProjects\pythonProject\venv\lib\site-packages\xmltodict.py", line 378, in parse
parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: mismatched tag: line 4, column 2
Unclosed client session
client_session:
Unclosed connector
connections: ['[(, 1349.796)]']
connector:
Process finished with exit code 1
___________________________________________________________________________________________________________
код
import python_weather
import asyncio
async def getweather():
# declare the client. format defaults to the metric system (celcius, km/h, etc.)
client = python_weather.Client(format=python_weather.IMPERIAL)
weather = await client.find("New York")
# returns the current day's forecast temperature (int)
print(weather.current.temperature)
# get the weather forecast for a few days
for forecast in weather.forecasts:
print(str(forecast.date), forecast.sky_text, forecast.temperature)
# close the wrapper once done
await client.close()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(getweather())
async def getweather():
# declare the client. format defaults to the metric system (celcius, km/h, etc.)
async with python_weather.Client(format=python_weather.IMPERIAL) as client:
# fetch a weather forecast from a city
weather = await client.get("Крым")
И в целом проблема в модуле python_weather. Там возникает ошибка парсинга полученных данных.
Плюс client = python_weather.Client(format=python_weather.IMPERIAL) скорее всего доже работать как контекстный менеджер, учитывая наличие await client.close().
Новые ошибки
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 23, in
asyncio.run(getweather())
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
return future.result()
File "C:\Users\user\PycharmProjects\pythonProject\main.py", line 9, in getweather
weather = await client.find("New York")
File "C:\Users\user\PycharmProjects\pythonProject\venv\lib\site-packages\python_weather\client.py", line 36, in find
return await self.http.request(location)
File "C:\Users\user\PycharmProjects\pythonProject\venv\lib\site-packages\python_weather\rest.py", line 19, in request
parsed = parse(await resp.text())
File "C:\Users\user\PycharmProjects\pythonProject\venv\lib\site-packages\xmltodict.py", line 378, in parse
parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: mismatched tag: line 4, column 2
Unclosed client session
client_session:
Unclosed connector
connections: ['[(, 174.203)]']
connector:
Fatal error on SSL transport
protocol:
transport: <_ProactorSocketTransport fd=628 read=<_OverlappedFuture cancelled>>
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 684, in _process_write_backlog
self._transport.write(chunk)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 361, in write
self._loop_writing(data=bytes(data))
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 397, in _loop_writing
self._write_fut = self._loop._proactor.send(self._sock, data)
AttributeError: 'NoneType' object has no attribute 'send'
Exception ignored in:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 321, in __del__
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 316, in close
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 593, in _start_shutdown
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 598, in _write_appdata
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 706, in _process_write_backlog
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\sslproto.py", line 720, in _fatal_error
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 151, in _force_close
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
RuntimeError: Event loop is closed
И к этому теперь на конце кода в любом случаи сиреневая черта
ElPerinson, во-первых, оформите код в своем основном вопросе в тег code.
Во-вторых, вы, по всей видимости, используете устаревшую версию python-weather, так как в этой библиотеке нет файла rest.py (последний номер версии 0.4.3, проверьте свою). В третьих, на странице библиотеки предлагается перед asyncio.run() добавить условие
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
В-четвертых, вы запускаете программу на 3.10, а не 3.11. Но это погоды, как я понимаю, не делает.