Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: await wasn't used with future #80

Closed
Tracked by #234
Windows200000 opened this issue Nov 25, 2022 · 51 comments
Closed
Tracked by #234

RuntimeError: await wasn't used with future #80

Windows200000 opened this issue Nov 25, 2022 · 51 comments
Labels
Bug Something isn't working Solved This issue has been resolved

Comments

@Windows200000
Copy link

After running for a while, the miner usually throws an error and terminates. When I try to run it again, it throws it on startup. It typically works the next day again. I'll update this if I can figure out the circumstances more precisely.

Fatal error encountered:

Traceback (most recent call last):
  File "main.py", line 178, in <module>
  File "asyncio\base_events.py", line 646, in run_until_complete
  File "twitch.py", line 670, in run
  File "twitch.py", line 712, in _run
  File "twitch.py", line 1417, in fetch_inventory
  File "gui.py", line 1247, in add_campaign
  File "cache.py", line 97, in get
  File "contextlib.py", line 199, in __aenter__
  File "twitch.py", line 1258, in request
  File "gui.py", line 1861, in coro_unless_closed
  File "aiohttp\client.py", line 1125, in send
  File "aiohttp\client.py", line 536, in _request
  File "aiohttp\connector.py", line 540, in connect
  File "aiohttp\connector.py", line 901, in _create_connection
  File "aiohttp\connector.py", line 1175, in _create_direct_connection
  File "aiohttp\connector.py", line 980, in _wrap_create_connection
  File "asyncio\base_events.py", line 1049, in create_connection
  File "asyncio\base_events.py", line 960, in _connect_sock
  File "asyncio\proactor_events.py", line 705, in sock_connect
RuntimeError: await wasn't used with future

Exiting...
@Windows200000
Copy link
Author

Windows200000 commented Nov 25, 2022

Also if there's a better channel to send you feedback on the current master i'll be happy to use that instead

@DevilXD DevilXD added the Bug Something isn't working label Nov 25, 2022
@DevilXD
Copy link
Owner

DevilXD commented Nov 25, 2022

Nah, issues like this are fine. Regarding the error though, this is something that comes from aiohttp and asyncio itself, and thus it's not my bug. As far as I'm aware, this can happen if your internet becomes unstable, which would explain why you're getting it after a restart too. There's not much I can do about it, other than just handle the exception and move on. Although if this is really caused by internet instability, then the "moving on" step may end up in an infinite loop, which I'd like to avoid.

@DevilXD
Copy link
Owner

DevilXD commented Nov 25, 2022

There's nothing on the aiohttp issues about this, so I'm guessing it's finally time to make an issue about it. This has came up at least 3 times in the past, for different people, and this is the 4th case. Will do so tomorrow.

@Windows200000
Copy link
Author

Nah, issues like this are fine. Regarding the error though, this is something that comes from aiohttp and asyncio itself, and thus it's not my bug. As far as I'm aware, this can happen if your internet becomes unstable, which would explain why you're getting it after a restart too. There's not much I can do about it, other than just handle the exception and move on. Although if this is really caused by internet instability, then the "moving on" step may end up in an infinite loop, which I'd like to avoid.

I have had some trouble with my ISP with tunneling in the past, but my internet seems to be fine now. I was even playing a game when it happened yesterday, so I'm pretty sure it's not the internet...

@DevilXD
Copy link
Owner

DevilXD commented Nov 26, 2022

No no, it is the internet connection's fault. But it's not a matter of losing it, more like it becoming temporarily unstable. Games and other software doesn't use aiohttp for connection purposes, so they're not running into this issue - as I said, it comes from aiohttp and asyncio internals, thus being limited to Python and those libraries specifically.

I'll just open an issue and see what the aiohttp team says about it.

@DevilXD
Copy link
Owner

DevilXD commented Nov 26, 2022

To file the issue, I'll need some information from you. Specifically:

  • Python Version (python --version)
  • aiohttp Version (python -m pip show aiohttp)
  • multidict Version (python -m pip show multidict)
  • yarl Version (python -m pip show yarl)
  • OS (Windows 10 x64 I assume?)

Remember to run these from the env folder, as that's where the libraries are actually installed.

@DevilXD
Copy link
Owner

DevilXD commented Nov 26, 2022

Also, I've pushed out 5e53448 to try and remedy this, as I saw some correlation between my code and what google was suggesting (not awaiting something properly). Theoretically it shouldn't matter, as awaiting calls the result method of the task anyway, but practically there's some extra code that runs before it does so:

obraz

You may want to try this out for a bit before we file an issue.

@Totesfleisch

This comment was marked as off-topic.

@DevilXD
Copy link
Owner

DevilXD commented Nov 26, 2022

@Totesfleisch There's a pinned issue with this exact error, that you seem to have missed: #68

Please only comment under the issue if you're getting the same (or at least very similar) traceback.

@Windows200000
Copy link
Author

I'm running the compiled version, so I ran the commands in the folder I used to build the exe.
Python 3.10.6
Win 10 22H2 (build 19045.2251)

Name: aiohttp
Version: 3.8.3
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: c:\users\arne\onedrive\desktop\building_tdminer\twitchdropsminer\env\lib\site-packages
Requires: aiosignal, async-timeout, attrs, charset-normalizer, frozenlist, multidict, yarl
Required-by:
Name: multidict
Version: 6.0.2
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: c:\users\arne\onedrive\desktop\building_tdminer\twitchdropsminer\env\lib\site-packages
Requires:
Required-by: aiohttp, yarl
Name: yarl
Version: 1.8.1
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: c:\users\arne\onedrive\desktop\building_tdminer\twitchdropsminer\env\lib\site-packages
Requires: idna, multidict
Required-by: aiohttp

I'll try 5e53448 and let you know if I encounter it again.

@Windows200000
Copy link
Author

Windows200000 commented Dec 3, 2022

So I left my PC running for a couple of days to test it, and it kept happening. I think it was a little less, but that might be due to other outside influences.
I now have the newest master, are you now catching the error and trying again? I'll let you know what I see, hopefully a bit sooner this time.

I also wrote a .bat file to update to the current master, which I thought might be helpful to other people testing or people using master bcs of critical bugs.

cd [folder to build in]
call git clone https://github.com/DevilXD/TwitchDropsMiner
cd TwitchDropsMiner
echo y|call setup_env.bat
call .\env\Scripts\activate.bat
call build.bat
copy ".\dist\Twitch Drops Miner (by DevilXD).exe" "[TDM install folder]" /Y
cmd /k

edit:
I got this traceback:

2022-12-04 00:43:03.322:	  ERROR:	Exception in task
Traceback (most recent call last):
  File "utils.py", line 96, in wrapper
  File "twitch.py", line 928, in _watch_loop
  File "channel.py", line 343, in send_watch
  File "channel.py", line 230, in get_spade_url
  File "contextlib.py", line 199, in __aenter__
  File "twitch.py", line 1269, in request
  File "gui.py", line 1929, in coro_unless_closed
  File "aiohttp\client.py", line 1125, in send
  File "aiohttp\client.py", line 536, in _request
  File "aiohttp\connector.py", line 540, in connect
  File "aiohttp\connector.py", line 901, in _create_connection
  File "aiohttp\connector.py", line 1175, in _create_direct_connection
  File "aiohttp\connector.py", line 980, in _wrap_create_connection
  File "asyncio\base_events.py", line 1049, in create_connection
  File "asyncio\base_events.py", line 960, in _connect_sock
  File "asyncio\proactor_events.py", line 705, in sock_connect
RuntimeError: await wasn't used with future

It's pretty similar but doesn't have "Exiting..." at the end. I guess that answers my question. I haven't seen it progress further after the error yet.

edit 2:
I can confirm the bot does continue mining some time after the error. Thank you!

@DevilXD
Copy link
Owner

DevilXD commented Dec 4, 2022

I can confirm the bot does continue mining some time after the error.

This error comes from the watch loop task. Thing is, the watch loop is only started at the very beginning of the application, and then not handled, checked or touched afterwards. If it dies because of an exception, the application will stop sending watch payloads to the current watching channel, and the mining will just stop. This won't end up in a fatal error like in your first case, because the watch loop is a task that can "swallow" all exceptions, while the first error came from the main loop that controls the application state and GUI.

I'll just file an aiohttp bug report and see what they say about this.

@Windows200000
Copy link
Author

Oh, you're right. I didn't look properly and confused the campaign and drop progress, so I thought it mined further. I guess we'll leave it at that, and we'll see if aiohttp do something...

@Windows200000
Copy link
Author

Just got another one, also on startup and with aiohttp, that isn't being caught. It seems to be really similar to the one I opened this issue with:

Fatal error encountered:

Traceback (most recent call last):
  File "main.py", line 171, in <module>
  File "asyncio\base_events.py", line 646, in run_until_complete
  File "twitch.py", line 677, in run
  File "twitch.py", line 719, in _run
  File "twitch.py", line 1428, in fetch_inventory
  File "gui.py", line 1277, in add_campaign
  File "cache.py", line 97, in get
  File "contextlib.py", line 199, in __aenter__
  File "twitch.py", line 1269, in request
  File "gui.py", line 1929, in coro_unless_closed
  File "aiohttp\client.py", line 1125, in send
  File "aiohttp\client.py", line 536, in _request
  File "aiohttp\connector.py", line 540, in connect
  File "aiohttp\connector.py", line 901, in _create_connection
  File "aiohttp\connector.py", line 1175, in _create_direct_connection
  File "aiohttp\connector.py", line 980, in _wrap_create_connection
  File "asyncio\base_events.py", line 1049, in create_connection
  File "asyncio\base_events.py", line 960, in _connect_sock
  File "asyncio\proactor_events.py", line 705, in sock_connect
RuntimeError: await wasn't used with future

Exiting...

Application Terminated.
Close the window to exit the application.

@DevilXD
Copy link
Owner

DevilXD commented Dec 4, 2022

Assuming you're running this from the built executable form, would it be possible for you to test running it from source? I'm wondering if PyInstaller does something weird to the event loop, but to check that, you'd need to try getting the same error running it from source.

@Windows200000
Copy link
Author

Windows200000 commented Dec 4, 2022

I ran it from the same folder I used to build the exe and got this:
(I changed the beginning of file paths, there were no spaces in them)

edit: I ran “env/Scripts/activate.bat” and then “python main.py” in the directory.

Fatal error encountered:

Traceback (most recent call last):
  File "[TDMiner_path]\TwitchDropsMiner\main.py", line 171, in <module>
    loop.run_until_complete(client.run())
  File "[Python310]\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "[TDMiner_path]\TwitchDropsMiner\twitch.py", line 677, in run
    await self._run()
  File "[TDMiner_path]\TwitchDropsMiner\twitch.py", line 719, in _run
    await self.fetch_inventory()
  File "[TDMiner_path]\TwitchDropsMiner\twitch.py", line 1428, in fetch_inventory
    await self.gui.inv.add_campaign(campaign)
  File "[TDMiner_path]\TwitchDropsMiner\gui.py", line 1277, in add_campaign
    campaign_image = await self._cache.get(campaign.image_url, size=(108, 144))
  File "[TDMiner_path]\TwitchDropsMiner\cache.py", line 97, in get
    async with self._twitch.request("GET", url) as response:
  File "[Python310]\lib\contextlib.py", line 199, in __aenter__
    return await anext(self.gen)
  File "[TDMiner_path]\TwitchDropsMiner\twitch.py", line 1269, in request
    response = await self.gui.coro_unless_closed(
  File "[TDMiner_path]\TwitchDropsMiner\gui.py", line 1929, in coro_unless_closed
    return await next(iter(done))
  File "[TDMiner_path]\TwitchDropsMiner\env\lib\site-packages\aiohttp\client.py", line 1125, in send
    return self._coro.send(arg)
  File "[TDMiner_path]\TwitchDropsMiner\env\lib\site-packages\aiohttp\client.py", line 536, in _request
    conn = await self._connector.connect(
  File "[TDMiner_path]\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "[TDMiner_path]\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "[TDMiner_path]\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "[TDMiner_path]\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 980, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "[Python310]\lib\asyncio\base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "[Python310]\lib\asyncio\base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "[Python310]\lib\asyncio\proactor_events.py", line 705, in sock_connect
    return await self._proactor.connect(sock, address)
RuntimeError: await wasn't used with future

Exiting...

Application Terminated.
Close the window to exit the application.

@DevilXD
Copy link
Owner

DevilXD commented Dec 5, 2022

@drachedachte1 That one is already known and solved for v15, see #68 for details.

Please only comment if you're having the same issue, json.decoder.JSONDecodeError: Extra data: line 1 column 128 (char 127) is quite different from RuntimeError: await wasn't used with future.

@DevilXD
Copy link
Owner

DevilXD commented Dec 13, 2022

@Windows200000 Been thinking about this one lately. I made you a slightly modified main.py to test with, it has some asyncio-debug things turned on. Please use the existing source code from the latest master, but with that file replaced with this attached one. Launch from source via activating the venv and python main.py, or via call ./env/Scripts/python main.py without having to activate the venv (your choice). python instead of pythonw specifically, because there might be some things printed out into the console that we'll need here.

File: main.zip

Oh, also, since it just occurred to me I haven't really suggested you this yet. From what I've tried to research about similar issues others were having, this particular error could be a result of an external application forcing the Python interpreter into ceasing creating a connection. To ensure that's not the case for you, please take a look at whatever programs you may have running in the background on your PC, specifically ones that can interfere with network traffic (antivirus, firewall, connection throughput enhancers, etc.), and try temporarily disabling those to see if they could be the cause here.

@Windows200000
Copy link
Author

I'll try this when I have time. I'm assuming I should try it after I find the .exe crashing. I only run windows defender and have no other network ulities.

@zarakibleach
Copy link

@Windows200000 Been thinking about this one lately. I made you a slightly modified main.py to test with, it has some asyncio-debug things turned on. Please use the existing source code from the latest master, but with that file replaced with this attached one. Launch from source via activating the venv and python main.py, or via call ./env/Scripts/python main.py without having to activate the venv (your choice). python instead of pythonw specifically, because there might be some things printed out into the console that we'll need here.

File: main.zip

Oh, also, since it just occurred to me I haven't really suggested you this yet. From what I've tried to research about similar issues others were having, this particular error could be a result of an external application forcing the Python interpreter into ceasing creating a connection. To ensure that's not the case for you, please take a look at whatever programs you may have running in the background on your PC, specifically ones that can interfere with network traffic (antivirus, firewall, connection throughput enhancers, etc.), and try temporarily disabling those to see if they could be the cause here.

I have the same issue as @Windows200000 but for me it just after log in

the mainpy provided by @DevilXD didin't solve the issue for me

PS : the same build works fine on my other machine with the same version of python 3.10.5

@DevilXD
Copy link
Owner

DevilXD commented Dec 15, 2022

the mainpy provided by @DevilXD didin't solve the issue for me

Because it was never supposed to solve the issue, in case you haven't realized it from my description, it's intended to enable extra debugging information that I'd very much need in order to determine where is the problem.

If you're having the same issue, please use it and comment with whatever the console spits out during runtime please.

@zarakibleach
Copy link

the mainpy provided by @DevilXD didin't solve the issue for me

Because it was never supposed to solve the issue, in case you haven't realized it from my description, it's intended to enable extra debugging information that I'd very much need in order to determine where is the problem.

If you're having the same issue, please use it and comment with whatever the console spits out during runtime please.

i ran the python main.py from activated env

and this is the output

python main.py
F:\leatest twitch drop\TwitchDropsMiner\gui.py:1758: ResourceWarning: unclosed file <_io.BufferedReader name='F:\leatest twitch drop\TwitchDropsMiner\pickaxe.ico'>
PhotoImage(
ResourceWarning: Enable tracemalloc to get the object allocation traceback

and the error in the GUI is

22:57:14: Please log in to continue.
22:57:27: Fatal error encountered:
22:57:27:
22:57:27: Traceback (most recent call last):
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\main.py", line 176, in
22:57:27: loop.run_until_complete(client.run())
22:57:27: File "C:\Users\zrkvm\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
22:57:27: return future.result()
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\twitch.py", line 682, in run
22:57:27: await self._run()
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\twitch.py", line 701, in _run
22:57:27: auth_state = await self.get_auth()
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\twitch.py", line 1357, in get_auth
22:57:27: await self._auth_state.validate()
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\twitch.py", line 434, in validate
22:57:27: await self._validate()
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\twitch.py", line 462, in _validate
22:57:27: self.access_token = await self._login()
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\twitch.py", line 317, in _login
22:57:27: async with self._twitch.request(
22:57:27: File "C:\Users\zrkvm\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 199, in aenter
22:57:27: return await anext(self.gen)
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\twitch.py", line 1382, in request
22:57:27: response = await self.gui.coro_unless_closed(
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\gui.py", line 1936, in coro_unless_closed
22:57:27: return await next(iter(done))
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\env\lib\site-packages\aiohttp\client.py", line 1125, in send
22:57:27: return self._coro.send(arg)
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\env\lib\site-packages\aiohttp\client.py", line 536, in _request
22:57:27: conn = await self._connector.connect(
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 540, in connect
22:57:27: proto = await self._create_connection(req, traces, timeout)
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 901, in _create_connection
22:57:27: _, proto = await self._create_direct_connection(req, traces, timeout)
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
22:57:27: transp, proto = await self._wrap_create_connection(
22:57:27: File "F:\leatest twitch drop\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 980, in _wrap_create_connection
22:57:27: return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
22:57:27: File "C:\Users\zrkvm\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1049, in create_connection
22:57:27: sock = await self._connect_sock(
22:57:27: File "C:\Users\zrkvm\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 960, in _connect_sock
22:57:27: await self.sock_connect(sock, address)
22:57:27: File "C:\Users\zrkvm\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 705, in sock_connect
22:57:27: return await self._proactor.connect(sock, address)
22:57:27: RuntimeError: await wasn't used with future
22:57:27:
22:57:27: Exiting...
22:57:28:
22:57:28: Application Terminated.
22:57:28: Close the window to exit the application.

@DevilXD
Copy link
Owner

DevilXD commented Dec 16, 2022

Hmm. That's just an unclosed executable icon file. Not sure why this happened, but also, this has pretty much a zero chance to interfere with anything relating to making internet requests that the error comes from, so entirely unrelated.

This leads me nowhere for now. You'll need to try finding the cause yourself, or someone from the aiohttp team will need to chime in under the aio-libs/aiohttp#7117 issue. Since I can't repro this on my side, I can't do much trying to fix it.

@Windows200000
Copy link
Author

So after not getting the error for a week I finally got it again, but when trying your main.py with the latest build I ran into #100. Can I use my cookies and settings from the .exe in the .py of the build I used to make the exe somehow? Otherwise, I'll have to wait til it crashes again, because I'm locked out...

@DevilXD
Copy link
Owner

DevilXD commented Dec 22, 2022

Can I use my cookies and settings from the .exe in the .py of the build I used to make the exe somehow?

Not sure if I'm getting this question right, but essentially, the executable form is the same as the source code form, the only difference is that the source code comes as a bunch of .py files, while the executable comes as a single file. So in both cases, you'll see the cache folder being created "next to" either the executable or py files, same goes for settings.json or cookies.jar. They function exactly the same, regardless if the application is packed into an exe or not.

So like, yes, you can use the same cookies.jar file with the source code version just fine. I recommend keeping at least two different cookie files around (I do one for exe and one for source) as backup if possible, they're valid for a year after they're created, and let you avoid dealing with login issues like in #100 case.

@Windows200000
Copy link
Author

Turns out I'm just dumb and didn't realize the files wouldn't be there if I didn't actually run the .py yet, so I wasn't sure about where to put them.

Here's the traceback:

22:12:05: Fatal error encountered:
22:12:05: 
22:12:05: Traceback (most recent call last):
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\main.py", line 176, in <module>
22:12:05:     loop.run_until_complete(client.run())
22:12:05:   File "C:\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
22:12:05:     return future.result()
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\twitch.py", line 682, in run
22:12:05:     await self._run()
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\twitch.py", line 724, in _run
22:12:05:     await self.fetch_inventory()
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\twitch.py", line 1560, in fetch_inventory
22:12:05:     await self.gui.inv.add_campaign(campaign)
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\gui.py", line 1296, in add_campaign
22:12:05:     benefit_images: list[PhotoImage] = await asyncio.gather(
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\cache.py", line 97, in get
22:12:05:     async with self._twitch.request("GET", url) as response:
22:12:05:   File "C:\Python310\lib\contextlib.py", line 199, in __aenter__
22:12:05:     return await anext(self.gen)
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\twitch.py", line 1397, in request
22:12:05:     response = await self.gui.coro_unless_closed(
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\gui.py", line 1936, in coro_unless_closed
22:12:05:     return await next(iter(done))
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\env\lib\site-packages\aiohttp\client.py", line 1125, in send
22:12:05:     return self._coro.send(arg)
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\env\lib\site-packages\aiohttp\client.py", line 536, in _request
22:12:05:     conn = await self._connector.connect(
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 540, in connect
22:12:05:     proto = await self._create_connection(req, traces, timeout)
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 901, in _create_connection
22:12:05:     _, proto = await self._create_direct_connection(req, traces, timeout)
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
22:12:05:     transp, proto = await self._wrap_create_connection(
22:12:05:   File "C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\env\lib\site-packages\aiohttp\connector.py", line 980, in _wrap_create_connection
22:12:05:     return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
22:12:05:   File "C:\Python310\lib\asyncio\base_events.py", line 1049, in create_connection
22:12:05:     sock = await self._connect_sock(
22:12:05:   File "C:\Python310\lib\asyncio\base_events.py", line 960, in _connect_sock
22:12:05:     await self.sock_connect(sock, address)
22:12:05:   File "C:\Python310\lib\asyncio\proactor_events.py", line 705, in sock_connect
22:12:05:     return await self._proactor.connect(sock, address)
22:12:05: RuntimeError: await wasn't used with future
22:12:05: 
22:12:05: Exiting...
22:12:06: 
22:12:06: Application Terminated.
22:12:06: Close the window to exit the application.

the terminal:

(env) C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner>python main.py
C:\Users\Arne\OneDrive\Desktop\building_TDMiner\TwitchDropsMiner\gui.py:1758: ResourceWarning: unclosed file <_io.BufferedReader name='C:\\Users\\Arne\\OneDrive\\Desktop\\building_TDMiner\\TwitchDropsMiner\\pickaxe.ico'>
  PhotoImage(
ResourceWarning: Enable tracemalloc to get the object allocation traceback

@DevilXD
Copy link
Owner

DevilXD commented Dec 22, 2022

I see. Still the same error heh? Also, I gotta deal with this icon error at some point, it should be just a matter of explicitly closing the file after creating the icon object.

@Windows200000
Copy link
Author

LMK if I can help you further somehow, and thanks for making this!

@DevilXD
Copy link
Owner

DevilXD commented Apr 30, 2023

An interesting find. This information should probably be put under the aiohttp issue for sure. I'll pass it there.

@ghost
Copy link

ghost commented Jun 7, 2023

looks like I have the same error in v15:

01:28:49: Fatal error encountered:
01:28:49:
01:28:49: Traceback (most recent call last):
01:28:49: File "main.py", line 175, in
01:28:49: File "asyncio\base_events.py", line 616, in run_until_complete
01:28:49: File "twitch.py", line 759, in run
01:28:49: File "twitch.py", line 778, in _run
01:28:49: File "twitch.py", line 1449, in get_auth
01:28:49: File "twitch.py", line 512, in validate
01:28:49: File "twitch.py", line 540, in _validate
01:28:49: File "twitch.py", line 295, in _oauth_login
01:28:49: File "contextlib.py", line 171, in aenter
01:28:49: File "twitch.py", line 1474, in request
01:28:49: File "gui.py", line 1946, in coro_unless_closed
01:28:49: File "aiohttp\client.py", line 1125, in send
01:28:49: File "aiohttp\client.py", line 536, in _request
01:28:49: File "aiohttp\connector.py", line 540, in connect
01:28:49: File "aiohttp\connector.py", line 901, in _create_connection
01:28:49: File "aiohttp\connector.py", line 1175, in _create_direct_connection
01:28:49: File "aiohttp\connector.py", line 980, in _wrap_create_connection
01:28:49: File "asyncio\base_events.py", line 1010, in create_connection
01:28:49: File "asyncio\base_events.py", line 924, in _connect_sock
01:28:49: File "asyncio\proactor_events.py", line 702, in sock_connect
01:28:49: RuntimeError: await wasn't used with future
01:28:49:
01:28:49: Exiting...
01:28:50:
01:28:50: Application Terminated.
01:28:50: Close the window to exit the application.

I have no reason to think that the problem is internet stability. It seems more like an OS problem. For me it started after I reinstalled Windows 7 with a hard drive change. Twitch itself works, but what a coincidence - if i open Twitch stream in VLC (player), i get certificate related error. At the same time, the same certificate in the browser is listed as safe/valid.

UPD: Tested on two different internet providers, result is the same

UPD2: So, instead of updating my outdated Windows version, i simply put the latest W7 distribution. And now the program works. If problem is really with certificates, the best thing you could do is adding feature to ignore this problem (again, like in VLC - there you can "accept" problematic certificate for 24 hours \ forever)

@DevilXD
Copy link
Owner

DevilXD commented Jul 5, 2023

@guihkx Could you try running your repro on this piece of code, if possible?

import asyncio
import aiohttp

async def main():
    async with aiohttp.request("https://google.com") as response:
       print(await response.text())

asyncio.run(main())

Since this issue now received an official CPython issue and has a repro, I'd like to find something smaller than this entire monster of a project, to repro the issue on. If you'd happen to have a Discord account (or would be willing to make one), we could sit down tomorrow, around 2-6 PM your time (assuming GMT-3), to hopefully narrow it down as much as possible. Well, unless it already fails on the code above x) I'd prefer Discord as it makes it easier to discuss things over interactive chat, rather than messages under issues like this one.

My Discord tag is DevilXD#4437, or simply devilxd with this new naming system Discord introduced recently.

@guihkx
Copy link
Contributor

guihkx commented Jul 6, 2023

Sure, no problem. I've added you on Discord.

The code as it is doesn't seem correct, btw:

Traceback (most recent call last):
  File "/home/gui/dev/aiohttp-repro/main.py", line 8, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/gui/dev/aiohttp-repro/main.py", line 5, in main
    async with aiohttp.request("https://google.com") as response:
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: request() missing 1 required positional argument: 'url'

@guihkx
Copy link
Contributor

guihkx commented Jul 6, 2023

I tried with this one instead (I grabbed it from their website):

import asyncio
import aiohttp

async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get('https://www.google.com/') as resp:
            print(await resp.text())

asyncio.run(main())

This is what I got:

$ SSL_CERT_DIR=/dev/null SSL_CERT_FILE=/dev/null python3 main.py
Traceback (most recent call last):
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1112, in create_connection
    transport, protocol = await self._create_connection_transport(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1145, in _create_connection_transport
    await waiter
  File "/usr/lib/python3.11/asyncio/sslproto.py", line 574, in _on_handshake_complete
    raise handshake_exc
  File "/usr/lib/python3.11/asyncio/sslproto.py", line 556, in _do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.11/ssl.py", line 979, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/gui/dev/aiohttp-repro/main.py", line 9, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/gui/dev/aiohttp-repro/main.py", line 6, in main
    async with session.get('https://www.google.com/') as resp:
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gui/dev/aiohttp-repro/env/lib/python3.11/site-packages/aiohttp/connector.py", line 982, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host www.google.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)')]

@DevilXD DevilXD mentioned this issue Jul 16, 2023
10 tasks
@DevilXD
Copy link
Owner

DevilXD commented Jul 16, 2023

The CPython issue on this has been "temporarily" closed, until someone from the aiohttp team (where this issue most likely is located at) can find some time to look at it.

python/cpython#106429

However, not all is lost - I now know what exactly causes the issue. With that, the only other option would be for me to rework the entire request method, so that it doesn't await on requests, and instead uses the context manager way only. This should resolve the issue, even without it getting fixed in aiohttp first.

I'll get to it when I can find some free time. This issue is now a part of v16 task list goals too: #234

@DevilXD
Copy link
Owner

DevilXD commented Nov 3, 2023

Okay, so I have some good news. There's been a PR made to aiohttp, that supposedly fixes this issue. In order to confirm that it works, I'd need someone who experiences this issue, to install the PR fix into the env folder with:

pip install --force-reinstall git+https://github.com/stalkerg/aiohttp@coroutine-wrapper-fix

If you'd be unsure how to do this, you can change the requirements.txt file's first line of aiohttp>2.0,<4.0 to:

aiohttp@git+https://github.com/stalkerg/aiohttp@coroutine-wrapper-fix

..., and then delete and recreate the env folder by running setup_env.bat again. After that, just run the application from source and see if the issue is still present.

PR link: aio-libs/aiohttp#7785

@DevilXD
Copy link
Owner

DevilXD commented Nov 3, 2023

Actually, nevermind - the PR has already been merged (aio-libs/aiohttp@a57dc31), and it looks like the fix will become available in v3.9 of aiohttp. According to aio-libs/aiohttp#7675, it's currently in beta testing, soon nearing official release. Once it is released, I'll update requirements.txt to require v3.9 of aiohttp specifically, and that should finally close this issue.

@stalkerg
Copy link

stalkerg commented Nov 3, 2023

Just in case - I am still interested in confirmation that it's really help for your case.

@DevilXD DevilXD mentioned this issue Nov 7, 2023
@MehmetCanWT
Copy link

MehmetCanWT commented Nov 7, 2023

i cant start the program i installed vc 14
im using latest v16 version of miner
Screenshot_20231108-001945_Microsoft Remote Desktop

@stalkerg
Copy link

stalkerg commented Nov 8, 2023

@MehmetCanWT I think you have ipv6 in your system, can you try to install the latest master branch of aiohttp and test again?

@ThisIsCyreX
Copy link
Contributor

ThisIsCyreX commented Dec 1, 2023

My Miner is now also dead after a Win11 reinstall.

//edit:
7 hours later. Without doing anything. It works again :)

@MehmetCanWT
Copy link

My Miner is now also dead after a Win11 reinstall

i reinstall old windows server to my server and it's working again

@DevilXD
Copy link
Owner

DevilXD commented Dec 2, 2023

a99227a should prevent this issue from happening, as explained above. Please try out the latest development build, and let me know if this issue is now resolved.

@DevilXD
Copy link
Owner

DevilXD commented Jan 27, 2024

I'm assuming this isn't a thing anymore, so it can finally be closed 😄

@DevilXD DevilXD closed this as completed Jan 27, 2024
@DevilXD DevilXD added the Solved This issue has been resolved label Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Solved This issue has been resolved
Projects
None yet
Development

No branches or pull requests

11 participants