dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
648 stars 153 forks source link

_get_build_number again don't working #636

Closed KhabarovaNina closed 6 months ago

KhabarovaNina commented 6 months ago

Summary

I get WARNING - Info API down. Falling back to manual fetching... when try

Reproduction Steps

I try create client client = discord.Client() and get "Info API down. Falling back to manual fetching... " This bug was fix in previous PR, but it comes back today

Code

client = discord.Client()

@client.event
async def on_ready():
    Logger.info("successful login as {0.user}".format(client))

Expected Results

Log "successful login as {0.user}".format(client)

Actual Results

WARNING - Info API down. Falling back to manual fetching...

System Information

python 3.10

Checklist

Additional Information

No response

NeutronBlast commented 6 months ago

Same issue here. I was looking at it and it seems to be throwing an error while getting the user agent, the site where they are getting grabbed from is returning an empty array, so, while that site gets patched I patched the code so it returns the hardcoded value if the response is an empty array, this is in case it goes down again for whatever reason.

async def _get_user_agent(session: ClientSession) -> str:
    """Fetches the latest Windows 10/Chrome user-agent."""
    try:
        request = await session.request('GET', 'https://jnrbsn.github.io/user-agents/user-agents.json', timeout=7)
        response = json.loads(await request.text())
        print(response)
        if len(response) > 0:
            return response[0]
        else:
            raise asyncio.TimeoutError
    except asyncio.TimeoutError:
        return (
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 '
            'Safari/537.36'
        )
ArcticSoftworks commented 6 months ago

I just had the same problem, I replaced _get_user_agent with the NeutronBlast patch and it gave me another index out of range error, to solve that I had to remove asyncio.TimeoutError from the except of _get_build_number, now it seems to work again for me


async def _get_build_number(session: ClientSession) -> int:  # Thank you Discord-S.C.U.M
    """Fetches client build number"""
    try:
        login_page_request = await session.get('https://discord.com/login', timeout=7)
        login_page = await login_page_request.text()
        build_url = 'https://discord.com/assets/' + re.compile(r'assets/+([a-z0-9]+)\.js').findall(login_page)[-2] + '.js'
        build_request = await session.get(build_url, timeout=7)
        build_file = await build_request.text()
        build_index = build_file.find('buildNumber') + 24
        return int(build_file[build_index : build_index + 6])
    except:
        _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
        return 9999
dolfies commented 6 months ago

This was already fixed on the latest commit!

PushkarOP commented 6 months ago

This was already fixed on the latest commit!

Still I am getting same issue

dolfies commented 6 months ago

This was already fixed on the latest commit!

Still I am getting same issue

You must update to the latest development version, install the library from git.