dolfies / discord.py-self

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

Discord.utils throwing error: Info API Down #597

Closed civiltox closed 10 months ago

civiltox commented 11 months ago

Summary

Info API Down

Reproduction Steps

opening main.py

Code

[2023-11-08 17:33:33] [INFO    ] discord.client: Logging in using static token.
[2023-11-08 17:33:38] [WARNING ] discord.utils: Info API down. Falling back to manual fetching...
Traceback (most recent call last):
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\main.py", line 12, in <module>
    bot.run('redacted')
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\client.py", line 938, in run
    asyncio.run(runner())
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\client.py", line 927, in runner
    await self.start(token, reconnect=reconnect)
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\client.py", line 857, in start
    await self.login(token)
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\client.py", line 698, in login
    data = await state.http.static_login(token.strip())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\http.py", line 991, in static_login
    await self.startup()
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\http.py", line 562, in startup
    self.super_properties, self.encoded_super_properties = sp, _ = await utils._get_info(session)
                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\utils.py", line 1446, in _get_info
    bn = await _get_build_number(session)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Admin\Desktop\ADVERTISING BOT\discord.py-self\discord\utils.py", line 1478, in _get_build_number
    return int(build_file[build_index : build_index + 6])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'ER_V2_'

Expected Results

its meant to work

Actual Results

its failing idk what else to put here

System Information

Checklist

Additional Information

No response

civiltox commented 11 months ago

i've tried installing brotli and updating aiohttp, both fail

DarlingYoko commented 11 months ago

Have same issue from today morning. specs: windows 11 python 3.11 discord.py-self - 2.0.0

brian-rdd commented 11 months ago

I retraced the action that the utils.py is performing to pull the build number and Discord may have changed the content of the .js file its scraping it from. Here is the relevant snippet that the code is currently pulling which is the source of the error:

DEV_NOTICE_STAGING:"Staging {buildNumber}",NOTIF_CENTER_V2_VIEW_SUMMARY

Looking at the code itself on line 1474:

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 asyncio.TimeoutError:
        _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
        return 9999

The exception handler is only catching asyncio.TimeoutError which means when the integer conversion fails, the whole thing fails.

Using the same .js file that is being evaluated, I found this line of code:

log("[BUILD INFO] Release Channel: ".concat(L,", Build Number: ").concat("244358",", Version Hash: ").concat("c189fc12370cb266be57cc968e278e86f7030f9b")),t.default.setTags({appContext:l.CURRENT_APP_CONTEXT}),S.default.initBasic(),N.default.init(),I.FocusRingManager.init(),O.init(),(0,R.cleanupTempFiles)()},599417:function(e,_,E){"use strict";E.r(_),E.d(_,{default:function(){return r}});var t=E("872717"),o=E("49111"),n=E("782340");class r extends t.default.V8APIError

The number 244358 does align with what Discord is telling me the build number is (and that number appears multiple times in that file near the text "Build Number"), so there are probably two fixes to be made, here:

  1. Extend the error handling to allow for other failures. If it can return a hardcoded value on timeout, why not always allow it?
  2. Add the necessary check to the function to account for both versions of the content: build_index = build_file.find('Build Number') + 25
NeutronBlast commented 11 months ago

Same error here

antomin commented 11 months ago

Same error here too

Quicksticks-oss commented 11 months ago

Same

omega9t9 commented 11 months ago

same error, since this morning

GSstarGamer commented 11 months ago

iv had my bot open for days, so its working. but when I restarted my computer. i got the same issue too. and 2 other people ik got it too.

aereobert commented 11 months ago

FIX: for util.py

I did not send a pull request, anyone who are interested can do this

async def _get_build_number(session: ClientSession) -> int:
    """Fetches client build number"""
    try:
        login_page_request = await session.get('https://discord.com/login', timeout=7)
        login_page = await login_page_request.text()
        # Find all potential JavaScript files that could contain the build number
        js_files = re.findall(r'assets/([a-z0-9]+)\.js', login_page)
        # Check each JavaScript file for the build number
        for js_file in js_files:
            build_url = f'https://discord.com/assets/{js_file}.js'
            build_request = await session.get(build_url, timeout=7)
            build_file = await build_request.text()
            # Look for 'buildNumber' in the JS file
            build_index = build_file.find('buildNumber') + len('buildNumber') + 2  # Adjusting the offset to after "buildNumber": 
            # Try to extract a six-digit number, assuming that the build number is 6 digits
            possible_build_number = build_file[build_index: build_index + 6]
            # If we find a number, return it
            if possible_build_number.isdigit():
                return int(possible_build_number)
        # If no build number is found in any file, fall back to the hardcoded value
        _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
        return 244594
    except asyncio.TimeoutError as e:
        _log.critical(f'Could not fetch client build number due to timeout: {e}')
        return 244594
apple050620312 commented 11 months ago

same

Entytaiment25 commented 11 months ago

I'm using discord.py-self 2.0.0, Python 3.11.5 and it's working for me somehow. Had problems yesterday when the Auth/API was down but since then worked perfectly again.

realdep commented 11 months ago

Having the same issue

Diwice commented 11 months ago

async def _get_build_number(session: ClientSession) -> int: """Fetches client build number""" try: login_page_request = await session.get('https://discord.com/login', timeout=7) login_page = await login_page_request.text()

Find all potential JavaScript files that could contain the build number

    js_files = re.findall(r'assets/([a-z0-9]+)\.js', login_page)
    # Check each JavaScript file for the build number
    for js_file in js_files:
        build_url = f'https://discord.com/assets/{js_file}.js'
        build_request = await session.get(build_url, timeout=7)
        build_file = await build_request.text()
        # Look for 'buildNumber' in the JS file
        build_index = build_file.find('buildNumber') + len('buildNumber') + 2  # Adjusting the offset to after "buildNumber": 
        # Try to extract a six-digit number, assuming that the build number is 6 digits
        possible_build_number = build_file[build_index: build_index + 6]
        # If we find a number, return it
        if possible_build_number.isdigit():
            return int(possible_build_number)
    # If no build number is found in any file, fall back to the hardcoded value
    _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
    return 244594
except asyncio.TimeoutError as e:
    _log.critical(f'Could not fetch client build number due to timeout: {e}')
    return 244594

thanks! solved the issue for me.

yamixiu123 commented 10 months ago

FIX: for util.py

I did not send a pull request, anyone who are interested can do this

async def _get_build_number(session: ClientSession) -> int:
    """Fetches client build number"""
    try:
        login_page_request = await session.get('https://discord.com/login', timeout=7)
        login_page = await login_page_request.text()
        # Find all potential JavaScript files that could contain the build number
        js_files = re.findall(r'assets/([a-z0-9]+)\.js', login_page)
        # Check each JavaScript file for the build number
        for js_file in js_files:
            build_url = f'https://discord.com/assets/{js_file}.js'
            build_request = await session.get(build_url, timeout=7)
            build_file = await build_request.text()
            # Look for 'buildNumber' in the JS file
            build_index = build_file.find('buildNumber') + len('buildNumber') + 2  # Adjusting the offset to after "buildNumber": 
            # Try to extract a six-digit number, assuming that the build number is 6 digits
            possible_build_number = build_file[build_index: build_index + 6]
            # If we find a number, return it
            if possible_build_number.isdigit():
                return int(possible_build_number)
        # If no build number is found in any file, fall back to the hardcoded value
        _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
        return 244594
    except asyncio.TimeoutError as e:
        _log.critical(f'Could not fetch client build number due to timeout: {e}')
        return 244594

god!

dolfies commented 10 months ago

Fixed in #596

Doocter commented 10 months ago

Fixed in #596

Also add it to "Releases" and to "PyPi" so to those who install via PIP can use it, I am sure 99% people install via PIP

apple050620312 commented 10 months ago

Fixed in #596

Also add it to "Releases" and to PyPi so to those who install with PIP can use it, I am 99% people install via PIP

SAME

trungnt2910 commented 10 months ago

Yeah, it's been quite a while since a release has been made...

jorney223 commented 10 months ago

Can you please help me how to fix this problem like the author, I don't understand it

jorney223 commented 10 months ago

FIX: for util.py

I did not send a pull request, anyone who are interested can do this

async def _get_build_number(session: ClientSession) -> int:
    """Fetches client build number"""
    try:
        login_page_request = await session.get('https://discord.com/login', timeout=7)
        login_page = await login_page_request.text()
        # Find all potential JavaScript files that could contain the build number
        js_files = re.findall(r'assets/([a-z0-9]+)\.js', login_page)
        # Check each JavaScript file for the build number
        for js_file in js_files:
            build_url = f'https://discord.com/assets/{js_file}.js'
            build_request = await session.get(build_url, timeout=7)
            build_file = await build_request.text()
            # Look for 'buildNumber' in the JS file
            build_index = build_file.find('buildNumber') + len('buildNumber') + 2  # Adjusting the offset to after "buildNumber": 
            # Try to extract a six-digit number, assuming that the build number is 6 digits
            possible_build_number = build_file[build_index: build_index + 6]
            # If we find a number, return it
            if possible_build_number.isdigit():
                return int(possible_build_number)
        # If no build number is found in any file, fall back to the hardcoded value
        _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
        return 244594
    except asyncio.TimeoutError as e:
        _log.critical(f'Could not fetch client build number due to timeout: {e}')
        return 244594

how how do I do that?

jorney223 commented 10 months ago

where should I insert it

Doocter commented 10 months ago

where should I insert it

Just install the development version here is guide: https://github.com/dolfies/discord.py-self#installing

To install the development version, do the following:

$ git clone https://github.com/dolfies/discord.py-self
$ cd discord.py-self
$ python3 -m pip install -U .
riqvip commented 10 months ago

where should I insert it

Just install the development version here is guide: https://github.com/dolfies/discord.py-self#installing

To install the development version, do the following:

$ git clone https://github.com/dolfies/discord.py-self
$ cd discord.py-self
$ python3 -m pip install -U .

Thanks so much. This worked!

whyont commented 9 months ago

Has this bug been fixed? I encountered the same problem。and I have cloned the developer version, but it doesn't work。Maybe my network connection is not up to this address, I need someone help🙏🏻

image