❗ Exceptions#

This is a list of all exceptions that may be raised by the library.

On the top level, there are two exceptions:

It is recommended to catch MeApiException and MeException separately. Here is an example:

from meapi import Me
from meapi.utils.exceptions import *

# Getting some user input:
phone_number = input("Enter your phone number: ")
activation_code = input("Enter your activation code: ")

try:
    me = Me(phone_number=phone_number, activation_code=activation_code)
except MeApiException as e:
    if isinstance(e, IncorrectActivationCode):
        print("Incorrect activation code!", e.reason)
    elif isinstance(e, ActivationCodeExpired):
        print("Activation code has expired!", e.reason)
    else:  # There are more exceptions, but they are not listed here (See the doc of the Me class)
        print("Unknown error!", e.msg, e.reason)
except MeException as e:
    if isinstance(e, NotValidPhoneNumber):
        print("Not a valid phone number!")
    else:
        print("Unknown error!", e.msg)
except ValueError as e:
    print("Wrong activation code. It must be a 6-digit number.")

# If there is no exception, the code will continue here.

This are the exceptions that may be raised by the API:

class meapi.utils.exceptions.MeApiException(http_status: int, msg: str, reason: Optional[str] = None)#
Raise this exception if http status code is bigger than 400.
  • Base class for all api exceptions.

Parameters:
  • http_status (int) – status code of the http request. =>400.

  • msg (str) – api error msg. for example: api_incorrect_activation_code.

  • reason (str) – Human reason to the error.

class meapi.utils.exceptions.IncorrectPwdToken(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the pwd token is incorrect. Happens when opening the account elsewhere.

class meapi.utils.exceptions.NewAccountException(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the account is new. Happens when trying to login to a new account. Provide NewAccountDetails in the Me constructor to continue.

class meapi.utils.exceptions.UnfinishedRegistration(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the registration is unfinished. Happens when trying to login to an account that is not registered. Provide NewAccountDetails in the Me constructor to continue.

class meapi.utils.exceptions.PhoneNumberDoesntExists(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the phone number doesn’t exist in me database.

class meapi.utils.exceptions.IncorrectActivationCode(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the activation code is incorrect.

class meapi.utils.exceptions.MaxValidateReached(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the max validate attempts via WhatsApp or Telegram reached.

class meapi.utils.exceptions.BlockedMaxVerifyReached(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the max verify attempts via sms or call reached.

class meapi.utils.exceptions.ActivationCodeExpired(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the activation code is correct but expired.

class meapi.utils.exceptions.SearchPassedLimit(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the search passed the limit. Happens when searching for a phone number too many times. The limit in the unofficial authentication method is 350 searches per day.

class meapi.utils.exceptions.ProfileViewPassedLimit(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the profile view passed the limit. Happens when viewing profiles too many times. The limit in the unofficial authentication method is 500 views per day.

class meapi.utils.exceptions.UserCommentsDisabled(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the user comments are disabled. Happens when trying to publish a comment to a user that disabled comments.

class meapi.utils.exceptions.UserCommentsPostingIsNotAllowed(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the user comments posting is not allowed. Happens when trying to publish a comment to a user that blocked you from commenting.

class meapi.utils.exceptions.CommentAlreadyApproved(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the comment is already approved. Happens when trying to approve a comment that is already approved.

class meapi.utils.exceptions.CommentAlreadyIgnored(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the comment is already ignored. Happens when trying to ignore a comment that is already ignored.

class meapi.utils.exceptions.BlockedAccount(http_status: int, msg: str, reason: Optional[str] = None)#

Raise this exception when the account is blocked. Happens when trying to login to a blocked account.

class meapi.utils.exceptions.ForbiddenRequest(http_status: int, msg: str, reason: Optional[str] = None)#
Raise this exception when the request is forbidden.
  • Happens in official authentication method when the access token is expired.


This are the exceptions that may be raised by the library:

class meapi.utils.exceptions.MeException(msg: str)#
Raises this exception when something goes wrong.
  • Base class for all library exceptions.

Parameters:

msg (str) – Reason of the exception.

class meapi.utils.exceptions.NotValidPhoneNumber(msg: Optional[str] = None)#

Raise this exception when the phone number is not valid.

class meapi.utils.exceptions.NotValidAccessToken(msg: Optional[str] = None)#

Raise this exception when the access token is not valid.

class meapi.utils.exceptions.NotLoggedIn(msg: Optional[str] = None)#
Raise this exception when the user is not logged in.
  • Happens when trying to call a method after calling me_client.logout(args)

Parameters:

msg (str) – Reason of the exception.

class meapi.utils.exceptions.NeedActivationCode(msg: Optional[str] = None)#
Raise this exception when the activation code is needed.
  • Happens when trying to login to a new account without providing the activation code in the constructor and the client initialized with interaction_mode = False.

Parameters:

msg (str) – Reason of the exception.

class meapi.utils.exceptions.ContactHasNoUser(msg: Optional[str] = None)#

Raise this exception when the contact has no user.

class meapi.utils.exceptions.FrozenInstance(cls: Type[MeModel], attr: str, msg: Optional[str] = None)#
Raise this exception when trying to change a frozen instance.
  • In some cases, the library uses frozen instances to prevent changing the attributes because in some models, reassigning the attributes will actually change the data on the server.

Parameters:
  • cls (MeModel) – The class of the frozen instance.

  • attr (str) – The attribute that is trying to be changed.

  • msg (str) – Reason of the exception. override the default message.

class meapi.utils.exceptions.BrokenCredentialsManager(msg: Optional[str] = None)#
Raise this exception when the credentials manager is broken.
  • Happens when login was successful but the credentials manager not providing the access token.

Parameters:

msg (str) – Reason of the exception.