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

[Errno 101] Cannot connect to host brawlapi.cf:443 #19

Closed
milan252525 opened this issue Feb 26, 2019 · 7 comments
Closed

[Errno 101] Cannot connect to host brawlapi.cf:443 #19

milan252525 opened this issue Feb 26, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@milan252525
Copy link

milan252525 commented Feb 26, 2019

Describe the bug

Traceback (most recent call last):
  File "lib/aiohttp/connector.py", line 601, in _create_direct_connection
    local_addr=self._local_addr)
  File "/usr/lib/python3.5/asyncio/base_events.py", line 695, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.5/asyncio/base_events.py", line 682, in create_connection
    yield from self.sock_connect(sock, address)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 402, in sock_connect
    return (yield from fut)
  File "/usr/lib/python3.5/asyncio/futures.py", line 363, in __iter__
    return self.result()  # May raise too.
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 407, in _sock_connect
    sock.connect(address)
OSError: [Errno 101] Network is unreachable

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

Traceback (most recent call last):
  File "lib/aiohttp/connector.py", line 304, in connect
    yield from self._create_connection(req)
  File "lib/aiohttp/connector.py", line 578, in _create_connection
    transport, proto = yield from self._create_direct_connection(req)
  File "lib/aiohttp/connector.py", line 624, in _create_direct_connection
    (req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 101] Can not connect to brawlapi.cf:443 [Network is unreachable]

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

Traceback (most recent call last):
  File "lib/discord/ext/commands/core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/home/newbot/labot/Red-DiscordBot/cogs/labs.py", line 25, in club
    club1 = await self.bs.get_club("V9GRP2C")
  File "/home/newbot/.local/lib/python3.5/site-packages/brawlstats/core.py", line 96, in _aget_model
    data, resp = await self._arequest(url)
  File "/home/newbot/.local/lib/python3.5/site-packages/brawlstats/core.py", line 83, in _arequest
    async with self.session.get(url, timeout=self.timeout, headers=self.headers) as resp:
  File "lib/aiohttp/client.py", line 565, in __aenter__
    self._resp = yield from self._coro
  File "lib/aiohttp/client.py", line 198, in _request
    conn = yield from self._connector.connect(req)
  File "lib/aiohttp/connector.py", line 314, in connect
    .format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 101] Cannot connect to host brawlapi.cf:443 ssl:True [Can not connect to brawlapi.cf:443 [Network is unreachable]]

Full Code

import discord
from discord.ext import commands
from .utils import checks 
import brawlstats
import asyncio

class LABS:
    def __init__(self, bot):
        self.bot = bot
        self.bs = brawlstats.Client('token', is_async=True)
    @commands.command(pass_context = True)
    async def club(self, ctx):
        club = await self.bs.get_club("VP2RL8P")
        embed = discord.Embed(description = club.description, colour = discord.Colour.blue())
        embed.set_author(name = club.name, icon_url = club.badge_url)
        embed.add_field(name = "Status", value = club.status)
        embed.add_field(name = "Members", value = str(club.members_count) + "/100")
        embed.add_field(name = "Status", value = club.status)
        await self.bot.say(embed = embed)
def setup(bot):
    bot.add_cog(LABS(bot))

Expected behavior
Connect to the API and retrieve data

Actual behavior
Can't connect, sync client works.

@SharpBit
Copy link
Owner

SharpBit commented Feb 26, 2019

Can you type in terminal pip show aiohttp and tell me the version? Could be something to do with the version discord.py that you're using uses.

Update: Try updating the wrapper using pip install -U brawlstats and see if it works

@SharpBit SharpBit added the bug Something isn't working label Feb 26, 2019
@milan252525
Copy link
Author

image

Wrapper updated, identical error:

aiohttp.errors.ClientOSError: [Errno 101] Cannot connect to host brawlapi.cf:443 ssl:True [Can not connect to brawlapi.cf:443 [Network is unreachable]]
[01/03/2019 17:02] ERROR red on_command_error 369: Exception in command 'club'
Traceback (most recent call last):
  File "lib/aiohttp/connector.py", line 601, in _create_direct_connection
    local_addr=self._local_addr)
  File "/usr/lib/python3.5/asyncio/base_events.py", line 695, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.5/asyncio/base_events.py", line 682, in create_connection
    yield from self.sock_connect(sock, address)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 402, in sock_connect
    return (yield from fut)
  File "/usr/lib/python3.5/asyncio/futures.py", line 363, in __iter__
    return self.result()  # May raise too.
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 407, in _sock_connect
    sock.connect(address)
OSError: [Errno 101] Network is unreachable

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

Traceback (most recent call last):
  File "lib/aiohttp/connector.py", line 304, in connect
    yield from self._create_connection(req)
  File "lib/aiohttp/connector.py", line 578, in _create_connection
    transport, proto = yield from self._create_direct_connection(req)
  File "lib/aiohttp/connector.py", line 624, in _create_direct_connection
    (req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 101] Can not connect to brawlapi.cf:443 [Network is unreachable]

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

Traceback (most recent call last):
  File "lib/discord/ext/commands/core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/home/newbot/labot/Red-DiscordBot/cogs/labs.py", line 25, in club
    club1 = await self.bs.get_club("V9GRP2C")
  File "/home/newbot/.local/lib/python3.5/site-packages/brawlstats/core.py", line 96, in _aget_model
  File "/home/newbot/.local/lib/python3.5/site-packages/brawlstats/core.py", line 83, in _arequest
    raise ServerError(url, code)
  File "lib/aiohttp/client.py", line 565, in __aenter__
    self._resp = yield from self._coro
  File "lib/aiohttp/client.py", line 198, in _request
    conn = yield from self._connector.connect(req)
  File "lib/aiohttp/connector.py", line 314, in connect
    .format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 101] Cannot connect to host brawlapi.cf:443 ssl:True [Can not connect to brawlapi.cf:443 [Network is unreachable]]

@SharpBit
Copy link
Owner

SharpBit commented Mar 3, 2019

Yeah, I don't really know how to fix this one... I've searched on google and stack overflow

  • I don't know if disabling verify_ssl is safe if that makes sense API enforces ssl
  • could try socket.AF_INET that but that breaks it for some network settings. This requires disabling ssl
  • Setting limit to 1 also would make the request synchronous.

Reference: aio-libs/aiohttp#2522

IF ANYONE KNOWS HOW TO FIX THIS, PLEASE SUBMIT A PULL REQUEST. REFER TO CONTRIBUTING.MD

@SharpBit SharpBit added the help wanted Extra attention is needed label Mar 3, 2019
@SharpBit
Copy link
Owner

SharpBit commented Mar 4, 2019

@milan252525 Maybe check your network settings/wifi? I can't seem to replicate your issue.

@SharpBit SharpBit mentioned this issue Mar 10, 2019
5 tasks
@SharpBit
Copy link
Owner

Fixed in v2.3.2 or 61a8308

To resolve the issue, pass in aiohttp.TCPConnector(use_dns_cache=False) into the client like such:

connector = aiohttp.TCPConnector(use_dns_cache=False)
client = brawlstats.Client(token, is_async=True, connector=connector)

OR if you want to use your own session:

connector = aiohttp.TCPConnector(use_dns_cache=False)
session = aiohttp.ClientSession(connector=connector)
client = brawlstats.Client(token, is_async=True, session=session)

@SharpBit SharpBit removed the help wanted Extra attention is needed label Mar 10, 2019
@SharpBit SharpBit pinned this issue Mar 2, 2020
@MuhammadShafeeq
Copy link

MuhammadShafeeq commented Jun 17, 2021

Bug:

It works in my pc but not in repl

  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: __enter__
Ignoring exception in command profile:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 70, in profile
    profile_info = secondary.get_info(tag)
  File "/home/runner/BrawlStarsBot/secondary.py", line 12, in get_info
    bs = brawlstats.Client(TOKEN, connector=connector)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/brawlstats/core.py", line 76, in __init__
    brawlers_info = self.get_brawlers()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/brawlstats/core.py", line 382, in get_brawlers
    return self._get_model(self.api.BRAWLERS, model=Brawlers)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/brawlstats/core.py", line 197, in _get_model
    data = self._request(url, use_cache)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/brawlstats/core.py", line 162, in _request
    with self.session.get(url, timeout=self.timeout, headers=self.headers) as resp:
AttributeError: __enter__

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

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: __enter__

Code:

def get_info(tag):
    connector = aiohttp.TCPConnector(use_dns_cache=False)
    bs = brawlstats.Client(TOKEN, connector=connector)
    player = bs.get_player(f"{tag}")
    return player

@SharpBit
Copy link
Owner

@MuhammadShafeeq this is not the same issue, this is a duplicate of issue #78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants