eLvErDe / yiimp-blocks-found-to-discord

Poll a Yiim pool block found result page and post a message to Discord chat room
BSD 3-Clause "New" or "Revised" License
1 stars 17 forks source link

async with aiohttp.ClientSession() as session: #2

Open goodthebest opened 6 years ago

goodthebest commented 6 years ago

@eLvErDe Adam I tried your script and end up getting this error, below is debug

image

any idea?

mtompkins commented 6 years ago

i forget how, but if you add a console output of the algo variable I'll let you know what it has just to confirm

eLvErDe commented 6 years ago

https://github.com/eLvErDe/yiimp/commit/0b72b984e6e207656f54e4765b48465185381238

mtompkins commented 6 years ago

Same

eLvErDe commented 6 years ago

Well sadly I won't be able to do more. I'm not using this algo variable AT ALL in this page, so without having the error_log with proper traceback...

mtompkins commented 6 years ago

Shit it may be permissions - I just realized I created the new file as root.

eLvErDe commented 6 years ago

I don't think so, it's still readable unless you're running a really weird umask.

Hold on, just saw somethings....

mtompkins commented 6 years ago

Well it wasn't permissions - that's confirmed

mtompkins commented 6 years ago

Also when I get a chance I'll set the VM to capture the php errors - that'll help

mtompkins commented 6 years ago

used this

ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");

and didn't see any errors when refreshing

eLvErDe commented 6 years ago

https://github.com/eLvErDe/yiimp/commit/4c5e517e2132907040666aa0c5b897e33673bdee

mtompkins commented 6 years ago

Progress!! screenshot from 2018-04-12 15-19-41 This is accurate

eLvErDe commented 6 years ago

So do you think it's working ?

mtompkins commented 6 years ago

Checking passing arguments now ... ?algo=all works checking other

eLvErDe commented 6 years ago

Wait, I'd like to do a small modification first

mtompkins commented 6 years ago

Yep - you nailed it!

mtompkins commented 6 years ago

I'll update the config and revert on the scraper -> discord

mtompkins commented 6 years ago

ok - I presume ?algo=all URL isn't going to change

eLvErDe commented 6 years ago

https://github.com/eLvErDe/yiimp/commit/543ac7541436920f0b60d1ce6ce1ca4f02aed6b7

mtompkins commented 6 years ago

I think it's ok but there is some weirdness to it - which may be memcache. If I go to ?algo=all - lists correctly, then go to a ?algo=neoscrypt it doesn't always update correctly. Not sure but I can live with it. I don't think anyone is going to switch that way.

eLvErDe commented 6 years ago

This is a final version I'd like to sent to tpruvot if you can do the following tests. Please also check the proper algorithm are shown in the page headers (inside parenthesis)

Nothing Nothing but change the algo by clicking on a different algorithm from the front page ?algo= (what happens ?) ?algo (what happens ?) ?algo=all ?algo=x17 ?algo=x17,neoscrypt,x11 ?algo=xé@17 (should be stripped down to x17)

Thanks !

mtompkins commented 6 years ago

Doing this in succession . . .

  1. Nothing | results in a random algo (like current implementation)
  2. Nothing w/click | results in the clicked algo
  3. ?algo= | no change on the page - displays #2
  4. ?algo | no change on the page - displays #2
  5. ?algo=all | displays all
  6. ?algo=x17 | displays x17
  7. ?algo=x17,neoscrypt,x11 | displays the 3 correctly
  8. ?algo=xé@17 | displays x17 as intended

Looks good

mtompkins commented 6 years ago

Bot is updated and active - will confirm findings after block - thanks for your work on this.

mtompkins commented 6 years ago

Hit a block I believe it should have caught - no announcement to discord. Will confirm on next.

eLvErDe commented 6 years ago

PR sent to tpruvot: https://github.com/tpruvot/yiimp/pull/256

mtompkins commented 6 years ago

Ok - a ton of SSL errors

Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: ERROR    [poll_yiimp_events        ] Exception occurred: ClientOSError: [Errno 111] Cannot connect to host some.yiimppool.com:443 ssl:True [Can not connect to some.yiimppool.com:443 [Connect call failed ('35.196.236.102', 443)]]
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: Traceback (most recent call last):
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 575, in _create_connection
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     server_hostname=hinfo['hostname'] if sslcontext else None)
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/base_events.py", line 695, in create_connection
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     raise exceptions[0]
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/base_events.py", line 682, in create_connection
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     yield from self.sock_connect(sock, address)
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/selector_events.py", line 402, in sock_connect
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     return (yield from fut)
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     yield self  # This tells Task to wait for completion.
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     future.result()
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     raise self._exception
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/selector_events.py", line 432, in _sock_connect_cb
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     raise OSError(err, 'Connect call failed %s' % (address,))
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: ConnectionRefusedError: [Errno 111] Connect call failed ('35.196.236.102', 443)
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: The above exception was the direct cause of the following exception:
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: Traceback (most recent call last):
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 307, in connect
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     transport, proto = yield from self._create_connection(req)
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 598, in _create_connection
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     (req.host, req.port, exc.strerror)) from exc
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: aiohttp.errors.ClientOSError: [Errno 111] Can not connect to some.yiimppool.com:443 [Connect call failed ('35.196.236.102', 443)]
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: The above exception was the direct cause of the following exception:
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: Traceback (most recent call last):
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/local/bin/yiimp-blocks-found-to-discord.py", line 126, in poll_yiimp_events
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     resp = await session.get(url)
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/client.py", line 499, in __await__
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     resp = yield from self._coro
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/client.py", line 174, in _request
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     conn = yield from self._connector.connect(req)
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 317, in connect
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]:     .format(key, exc.strerror)) from exc
Apr 12 15:46:58 yiimp-blocks-found-to-discord[19179]: aiohttp.errors.ClientOSError: [Errno 111] Cannot connect to host some.yiimppool.com:443 ssl:True [Can not connect to some.yiimppool.com:443 [Connect call failed ('35.196.236.102', 443)]]
Apr 12 15:47:02 yiimp-blocks-found-to-discord[19179]: INFO     [refresh_st_exc_markets   ] Refreshed
Apr 12 15:47:02 yiimp-blocks-found-to-discord[19179]: INFO     [refresh_cryptopia_markets] Refreshed
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: ERROR    [poll_yiimp_events        ] Exception occurred: ClientOSError: [Errno 111] Cannot connect to host some.yiimppool.com:443 ssl:True [Can not connect to some.yiimppool.com:443 [Connect call failed ('35.196.236.102', 443)]]
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: Traceback (most recent call last):
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 575, in _create_connection
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     server_hostname=hinfo['hostname'] if sslcontext else None)
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/base_events.py", line 695, in create_connection
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     raise exceptions[0]
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/base_events.py", line 682, in create_connection
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     yield from self.sock_connect(sock, address)
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/selector_events.py", line 402, in sock_connect
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     return (yield from fut)
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     yield self  # This tells Task to wait for completion.
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     future.result()
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     raise self._exception
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3.5/asyncio/selector_events.py", line 432, in _sock_connect_cb
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     raise OSError(err, 'Connect call failed %s' % (address,))
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: ConnectionRefusedError: [Errno 111] Connect call failed ('35.196.236.102', 443)
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: The above exception was the direct cause of the following exception:
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: Traceback (most recent call last):
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 307, in connect
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     transport, proto = yield from self._create_connection(req)
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 598, in _create_connection
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     (req.host, req.port, exc.strerror)) from exc
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: aiohttp.errors.ClientOSError: [Errno 111] Can not connect to some.yiimppool.com:443 [Connect call failed ('35.196.236.102', 443)]
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: The above exception was the direct cause of the following exception:
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: Traceback (most recent call last):
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/local/bin/yiimp-blocks-found-to-discord.py", line 126, in poll_yiimp_events
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     resp = await session.get(url)
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/client.py", line 499, in __await__
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     resp = yield from self._coro
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/client.py", line 174, in _request
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     conn = yield from self._connector.connect(req)
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:   File "/usr/lib/python3/dist-packages/aiohttp/connector.py", line 317, in connect
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]:     .format(key, exc.strerror)) from exc
Apr 12 15:47:03 yiimp-blocks-found-to-discord[19179]: aiohttp.errors.ClientOSError: [Errno 111] Cannot connect to host some.yiimppool.com:443 ssl:True [Can not connect to some.yiimppool.com:443 [Connect call failed ('35.196.236.102', 443)]]
mtompkins commented 6 years ago

35.196.236.102 isn't me (some.yiimppool.com) .. presume it's discord?

eLvErDe commented 6 years ago

No it's coming from the "poll_yiimp_events" coroutine. Are you sure to have https:// in the URL ? That's weird. I have no idea what could be 35.196.236.102

mtompkins commented 6 years ago

Yes it is correct. I also tried a curl to the ?algo=all and it comes back fine. A curl to the webhook addy also returns correctly.

eLvErDe commented 6 years ago

ConnectionRefusedError: [Errno 111] Connect call failed ('35.196.236.102', 443)

Well that's definetely the address you are trying to connect on....

eLvErDe commented 6 years ago

You did not have this issue before right ? Can you remove ?algo=all from the URL and confirm it's working again ?

eLvErDe commented 6 years ago

That might be again related to the prehistoric version of aiohttp you are using (not being able to handle query param as part of the URL itself)

mtompkins commented 6 years ago

Correct, and it never worked because it always had the wrong algo. I agree and it was my intent to try the newer aiohttp and see if that solved it.

eLvErDe commented 6 years ago

So removing algo=all make the aiohttp call works ?

mtompkins commented 6 years ago

I don't know and won't be able to tell. It brings us back to where we started with no blocks on an algo with no action.

mtompkins commented 6 years ago

Testing now with current v. of aiohttp - will revert on block.

eLvErDe commented 6 years ago

Well no we are not ! We patched YIIMP code to avoid a proper page to be scrapped.

Problem is that at the moment I don't understand your testing.

mtompkins commented 6 years ago

Removing the parameter puts us right back to where we started, just as in the first test you asked me to run. We arrive at a "random" page as I explicitly indicated above.

  1. Nothing | results in a random algo (like current implementation)

The page does not default to all without a parameter, so again, we are right back to the beginning of this experiment. I'm on the new aiohttp and will revert with that outcome.

eLvErDe commented 6 years ago

Yes I get that, but if the aiohttp traceback is gone when you remove ?algo=all, it means your aiohttp cannot handle that and that would be easy to fix.

mtompkins commented 6 years ago

How long should it be from a posted new block until the python script picks it up? Is there a poll period? I had a block at :03 and there was no evidence of it (no error either) in watching the logs for 7 minutes. This is with the master branch and most current aiohttp

Once I understand the poll period I'll have a look at this recent work again.

eLvErDe commented 6 years ago

It's nearly live but the block has to appear while the script is already running. If you started the script and the block was found already it won't find it

mtompkins commented 6 years ago

OK - that's what I anticipated. The script was started before the block was found, by minutes. I've reverted to the old aiohttp and your current changes. I'll wait for a block, capture out, then try again without the parameter.

eLvErDe commented 6 years ago

The easiest way would be to give me your pool address ;-) By private email if you prefer.

mtompkins commented 6 years ago

I appreciate that, unfortunately isn't an option atm.

eLvErDe commented 6 years ago

Which version of aiohttp are you running ? Default one from Ubuntu xenial? I'll start my script in a docker container to confirm if it can work with such an old version

mtompkins commented 6 years ago

Now on:
python3-bs4 is already the newest version (4.4.1-1). python3-aiohttp is already the newest version (0.20.2-1)

eLvErDe commented 6 years ago

For the record I created the following docker file:

FROM ubuntu:xenial

MAINTAINER Adam Cecile <acecile@le-vert.net>

ENV TERM xterm
ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
RUN apt update && apt -y -o 'Dpkg::Options::=--force-confdef' -o 'Dpkg::Options::=--force-confold' --no-install-recommends install wget ca-certificates python3-bs4 python3-html5lib python3-aiohttp && rm -rf /var/lib/apt/lists/*

# Install script from legacy branch
RUN wget https://raw.githubusercontent.com/eLvErDe/yiimp-blocks-found-to-discord/old-aiohttp-compat/yiimp-blocks-found-to-discord.py -O /root/yiimp-blocks-found-to-discord.py && chmod 0755 /root/yiimp-blocks-found-to-discord.py

Built using:

docker build -t test-yiimp-xenial . -f Dockerfile.ubuntu.xenial --no-cache

Run using:

docker run -it --rm test-yiimp-xenial /root/yiimp-blocks-found-to-discord.py -p https://pool.ionik.fr/site/found_results?algo=all -d https://discordapp.com/api/webhooks/123/345

And it's polling and finding blocks just fine however, posting to Discords is still fucked up, thanks to aiohttp 0.20.

mtompkins commented 6 years ago

Yea I figured (purely guessing) it has something to do with TLS and this older aiohttp. Did you test your master branch and current aiohttp because Discord didn't work on that for me (unless I missed something)?

eLvErDe commented 6 years ago

It's running on my Debian Buster with aiohttp 3.0.1-1 just fine. I'm pretty sure I was running 2.x when writing this script

mtompkins commented 6 years ago

OK I'll try 3.0.1

eLvErDe commented 6 years ago

Not needed I'm fixing remaining issues with 0.20 in the legacy branch.