Skip to content

Commit

Permalink
fix: fixed 404 error for get_uuid & get_username (#59)
Browse files Browse the repository at this point in the history
* fix: fixed 404 error for get_uuid & get_username

* chore: implicit Optional mypy
  • Loading branch information
Lucino772 authored Feb 4, 2023
1 parent 35f2e79 commit d8b9cf3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mojang/api/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def _acquire_microsoft_token(self, code: str) -> Tuple[str, str]:

@overload
def get_session(
self, username: str, password: str, client_token: str = None
self, username: str, password: str, client_token: Optional[str] = None
) -> MojangAuthenticatedUser:
"""Authenticate with a Mojang Account
Expand Down
21 changes: 16 additions & 5 deletions mojang/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import requests

from ..exceptions import InvalidName
from ..exceptions import InvalidName, MethodNotAllowed, ServerError
from . import helpers, urls
from .models import Cape, Skin
from .structures import ServiceStatus, UnauthenticatedProfile
Expand Down Expand Up @@ -67,9 +67,14 @@ def get_uuid(username: str) -> Optional[str]:
raise InvalidName()

response = requests.get(urls.api_get_uuid(username))
code, data = helpers.err_check(response)
code, data = helpers.err_check(
response,
(405, MethodNotAllowed),
(500, ServerError),
use_defaults=False,
)

if code == 204:
if code == 404:
return None

return data["id"]
Expand Down Expand Up @@ -126,9 +131,15 @@ def get_username(uuid: str) -> Optional[str]:
'Notch'
"""
response = requests.get(urls.api_get_username(uuid))
code, data = helpers.err_check(response, (400, ValueError))
code, data = helpers.err_check(
response,
(400, ValueError),
(405, MethodNotAllowed),
(500, ServerError),
use_defaults=False,
)

if code == 204:
if code == 404:
return None

return data["name"]
Expand Down
10 changes: 7 additions & 3 deletions mojang/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def __init__(
self,
source: str,
variant: str,
id: str = None,
state: str = None,
id: Optional[str] = None,
state: Optional[str] = None,
load: bool = True,
) -> None:
super().__init__(source, load=load)
Expand Down Expand Up @@ -158,7 +158,11 @@ class Cape(_Resource):
"""

def __init__(
self, source: str, id: str = None, state: str = None, load: bool = True
self,
source: str,
id: Optional[str] = None,
state: Optional[str] = None,
load: bool = True,
) -> None:
super().__init__(source, load=load)
self.__id = id
Expand Down
5 changes: 4 additions & 1 deletion mojang/api/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt
import typing as t

import jwt
import requests
Expand Down Expand Up @@ -247,7 +248,9 @@ def hide_user_cape(access_token: str):


def owns_minecraft(
access_token: str, verify_sig: bool = False, public_key: str = None
access_token: str,
verify_sig: bool = False,
public_key: t.Optional[str] = None,
) -> bool:
"""Returns True if the authenticated user owns minecraft
Expand Down
2 changes: 1 addition & 1 deletion mojang/minecraft/slp/pre_netty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def ping_fe01(
sock: socket.socket,
hostname: str = None,
hostname: Optional[str] = None,
port: int = -1,
):
if hostname is not None and len(hostname) > 0 and port > 0:
Expand Down

0 comments on commit d8b9cf3

Please sign in to comment.