Skip to content

exceptions

Contains exceptions used by ro.py.

AssetNotFound

Bases: ItemNotFound

Raised for invalid asset IDs.

Source code in roblox/utilities/exceptions.py
187
188
189
190
191
class AssetNotFound(ItemNotFound):
    """
    Raised for invalid asset IDs.
    """
    pass

BadRequest

Bases: HTTPException

HTTP exception raised for status code 400.

Source code in roblox/utilities/exceptions.py
100
101
102
class BadRequest(HTTPException):
    """HTTP exception raised for status code 400."""
    pass

BadgeNotFound

Bases: ItemNotFound

Raised for invalid badge IDs.

Source code in roblox/utilities/exceptions.py
194
195
196
197
198
class BadgeNotFound(ItemNotFound):
    """
    Raised for invalid badge IDs.
    """
    pass

Forbidden

Bases: HTTPException

HTTP exception raised for status code 403. This usually means the X-CSRF-Token was not properly provided.

Source code in roblox/utilities/exceptions.py
109
110
111
class Forbidden(HTTPException):
    """HTTP exception raised for status code 403. This usually means the X-CSRF-Token was not properly provided."""
    pass

GroupNotFound

Bases: ItemNotFound

Raised for invalid group IDs.

Source code in roblox/utilities/exceptions.py
201
202
203
204
205
class GroupNotFound(ItemNotFound):
    """
    Raised for invalid group IDs.
    """
    pass

HTTPException

Bases: RobloxException

Exception that's raised when an HTTP request fails.

Attributes:

Name Type Description
response Response

The HTTP response object.

status int

The HTTP response status code.

errors List[ResponseError]

A list of Roblox response errors.

Source code in roblox/utilities/exceptions.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class HTTPException(RobloxException):
    """
    Exception that's raised when an HTTP request fails.

    Attributes:
        response: The HTTP response object.
        status: The HTTP response status code.
        errors: A list of Roblox response errors.
    """

    def __init__(self, response: Response, errors: Optional[list] = None):
        """
        Arguments:
            response: The raw response object.
            errors: A list of errors.
        """
        self.response: Response = response
        self.status: int = response.status_code
        self.errors: List[ResponseError]

        if errors:
            self.errors = [
                ResponseError(data=error_data) for error_data in errors
            ]
        else:
            self.errors = []

        if self.errors:
            error_string = self._generate_string()
            super().__init__(
                f"{response.status_code} {response.reason_phrase}: {response.url}.\n\nErrors:\n{error_string}")
        else:
            super().__init__(f"{response.status_code} {response.reason_phrase}: {response.url}")

    def _generate_string(self) -> str:
        parsed_errors = []
        for error in self.errors:
            # Make each error into a parsed string
            parsed_error = f"\t{error.code}: {error.message}"
            error_messages = []

            error.user_facing_message and error_messages.append(f"User-facing message: {error.user_facing_message}")
            error.field and error_messages.append(f"Field: {error.field}")
            error.retryable and error_messages.append(f"Retryable: {error.retryable}")

            if error_messages:
                error_message_string = "\n\t\t".join(error_messages)
                parsed_error += f"\n\t\t{error_message_string}"

            parsed_errors.append(parsed_error)

        # Turn the parsed errors into a joined string
        return "\n".join(parsed_errors)

__init__(response, errors=None)

Parameters:

Name Type Description Default
response Response

The raw response object.

required
errors Optional[list]

A list of errors.

None
Source code in roblox/utilities/exceptions.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(self, response: Response, errors: Optional[list] = None):
    """
    Arguments:
        response: The raw response object.
        errors: A list of errors.
    """
    self.response: Response = response
    self.status: int = response.status_code
    self.errors: List[ResponseError]

    if errors:
        self.errors = [
            ResponseError(data=error_data) for error_data in errors
        ]
    else:
        self.errors = []

    if self.errors:
        error_string = self._generate_string()
        super().__init__(
            f"{response.status_code} {response.reason_phrase}: {response.url}.\n\nErrors:\n{error_string}")
    else:
        super().__init__(f"{response.status_code} {response.reason_phrase}: {response.url}")

InternalServerError

Bases: HTTPException

HTTP exception raised for status code 500. This usually means that there was an issue on Roblox's end, but due to faulty coding on Roblox's part this can sometimes mean that an endpoint used internally was disabled or that invalid parameters were passed.

Source code in roblox/utilities/exceptions.py
130
131
132
133
134
135
136
class InternalServerError(HTTPException):
    """
    HTTP exception raised for status code 500.
    This usually means that there was an issue on Roblox's end, but due to faulty coding on Roblox's part this can
    sometimes mean that an endpoint used internally was disabled or that invalid parameters were passed.
    """
    pass

InvalidRole

Bases: RobloxException

Raised when a role doesn't exist.

Source code in roblox/utilities/exceptions.py
157
158
159
160
161
class InvalidRole(RobloxException):
    """
    Raised when a role doesn't exist.
    """
    pass

ItemNotFound

Bases: RobloxException

Raised for invalid items.

Source code in roblox/utilities/exceptions.py
172
173
174
175
176
177
178
179
180
181
182
183
184
class ItemNotFound(RobloxException):
    """
    Raised for invalid items.
    """

    def __init__(self, message: str, response: Optional[Response] = None):
        """
        Arguments:
            response: The raw response object.
        """
        self.response: Optional[Response] = response
        self.status: Optional[int] = response.status_code if response else None
        super().__init__(message)

__init__(message, response=None)

Parameters:

Name Type Description Default
response Optional[Response]

The raw response object.

None
Source code in roblox/utilities/exceptions.py
177
178
179
180
181
182
183
184
def __init__(self, message: str, response: Optional[Response] = None):
    """
    Arguments:
        response: The raw response object.
    """
    self.response: Optional[Response] = response
    self.status: Optional[int] = response.status_code if response else None
    super().__init__(message)

NoMoreItems

Bases: RobloxException

Raised when there are no more items left to iterate through.

Source code in roblox/utilities/exceptions.py
164
165
166
167
168
class NoMoreItems(RobloxException):
    """
    Raised when there are no more items left to iterate through.
    """
    pass

NotFound

Bases: HTTPException

HTTP exception raised for status code 404. This usually means we have an internal URL issue - please make a GitHub issue about this!

Source code in roblox/utilities/exceptions.py
114
115
116
117
118
119
class NotFound(HTTPException):
    """
    HTTP exception raised for status code 404.
    This usually means we have an internal URL issue - please make a GitHub issue about this!
    """
    pass

PlaceNotFound

Bases: ItemNotFound

Raised for invalid place IDs.

Source code in roblox/utilities/exceptions.py
208
209
210
211
212
class PlaceNotFound(ItemNotFound):
    """
    Raised for invalid place IDs.
    """
    pass

PluginNotFound

Bases: ItemNotFound

Raised for invalid plugin IDs.

Source code in roblox/utilities/exceptions.py
215
216
217
218
219
class PluginNotFound(ItemNotFound):
    """
    Raised for invalid plugin IDs.
    """
    pass

ResponseError

Represents an error returned by a Roblox game server.

Attributes:

Name Type Description
code int

The error code.

message Optional[str]

The error message.

user_facing_message Optional[str]

A more simple error message intended for frontend use.

field Optional[str]

The field causing this error.

retryable Optional[str]

Whether retrying this exception could supress this issue.

Source code in roblox/utilities/exceptions.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class ResponseError:
    """
    Represents an error returned by a Roblox game server.

    Attributes:
        code: The error code.
        message: The error message.
        user_facing_message: A more simple error message intended for frontend use.
        field: The field causing this error.
        retryable: Whether retrying this exception could supress this issue.
    """

    def __init__(self, data: dict):
        self.code: int = data["code"]
        self.message: Optional[str] = data.get("message")
        self.user_facing_message: Optional[str] = data.get("userFacingMessage")
        self.field: Optional[str] = data.get("field")
        self.retryable: Optional[str] = data.get("retryable")

RobloxException

Bases: Exception

Base exception for all of ro.py.

Source code in roblox/utilities/exceptions.py
13
14
15
16
17
class RobloxException(Exception):
    """
    Base exception for all of ro.py.
    """
    pass

TooManyRequests

Bases: HTTPException

HTTP exception raised for status code 429. This means that Roblox has ratelimited you.

Source code in roblox/utilities/exceptions.py
122
123
124
125
126
127
class TooManyRequests(HTTPException):
    """
    HTTP exception raised for status code 429.
    This means that Roblox has [ratelimited](https://en.wikipedia.org/wiki/Rate_limiting) you.
    """
    pass

Unauthorized

Bases: HTTPException

HTTP exception raised for status code 401. This usually means you aren't properly authenticated.

Source code in roblox/utilities/exceptions.py
105
106
class Unauthorized(HTTPException):
    """HTTP exception raised for status code 401. This usually means you aren't properly authenticated."""

UniverseNotFound

Bases: ItemNotFound

Raised for invalid universe IDs.

Source code in roblox/utilities/exceptions.py
222
223
224
225
226
class UniverseNotFound(ItemNotFound):
    """
    Raised for invalid universe IDs.
    """
    pass

UserNotFound

Bases: ItemNotFound

Raised for invalid user IDs or usernames.

Source code in roblox/utilities/exceptions.py
229
230
231
232
233
class UserNotFound(ItemNotFound):
    """
    Raised for invalid user IDs or usernames.
    """
    pass

get_exception_from_status_code(code)

Gets an exception that should be raised instead of the generic HTTPException for this status code.

Source code in roblox/utilities/exceptions.py
149
150
151
152
153
def get_exception_from_status_code(code: int) -> Type[HTTPException]:
    """
    Gets an exception that should be raised instead of the generic HTTPException for this status code.
    """
    return _codes_exceptions.get(code) or HTTPException