summer / mojang

A wrapper for the Mojang API and Minecraft website
MIT License
35 stars 6 forks source link

"mojang.errors.NotFound: HTTP 404. This resource does not exist." On login with bearer token #38

Open ghost opened 1 year ago

ghost commented 1 year ago

When trying to login with a bearer token, It throws a 404 not found error. This is my code, i am trying to use 2 accounts:

        try:
            client1 = Client("EMAIL", "PASS")
        except errors.LoginFailure:
            QtWidgets.QMessageBox.about(self, "Error", "Invalid main account")
            return

        try:
            client2 = Client(bearer_token = "TOKEN")

        except errors.LoginFailure:
            QtWidgets.QMessageBox.about(self, "Error", "Invalid second account")
            return

It should be a valid token. Its 435 characters long and contains a dot.

summer commented 1 year ago

Hi, I've tried to replicate this issue but it's not happening for me. Is there anything different about the Minecraft account?

Can you check if it happens when you use this code?

from mojang import Client

client = Client("EMAIL", "PASS")

client2 = Client(bearer_token=client.bearer_token)

Also, have you tried enabling debug mode?

from mojang import Client

client = Client(bearer_token="BEARER_TOKEN", debug_mode=True)

If you can find out the specific endpoint that's returning a HTTP 404, that would help.

ghost commented 1 year ago

First of all. thanks for your response @summer.

I have now switched to using 2 accounts with email:pass and without the token. But i am still getting a 404 error.

The account(s) are XBOX life if this makes a difference.

gtvCH commented 1 year ago

This error occurs, when you use a brand-new account which has no name set yet. Client instantiation is not possible. Traceback:

Traceback (most recent call last):
  File "/home/username/test.py", line 7, in <module>
    client = Client("email", "password")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mojang/client.py", line 63, in __init__
    self._validate_session()
  File "/usr/lib/python3.11/site-packages/mojang/client.py", line 95, in _validate_session
    if not self._has_minecraft_profile():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mojang/client.py", line 75, in _has_minecraft_profile
    resp = self.request("get", f"{_BASE_API_URL}/minecraft/profile")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mojang/_http_client.py", line 84, in request
    raise NotFound
mojang.errors.NotFound: HTTP 404. This resource does not exist.

(To avoid misunderstanding: It seems to be a bug in the library, not in the code of @MatrixByt3s) Hope this helps to fix the bug :)

ProtDos commented 2 months ago

Hey. I found the answer to why this is. This is when the user has not set a username yet / is a fresh account. I'll maybe open a pull request for it.