Skip to content

Commit

Permalink
Handle AttributeError: 'dict' object has no attribute 'name' error
Browse files Browse the repository at this point in the history
Probably broke 2FA lul
  • Loading branch information
UltimaHoarder committed Apr 16, 2021
1 parent fdf6550 commit 87237e2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 43 deletions.
94 changes: 55 additions & 39 deletions apis/onlyfans/onlyfans.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ def handle_refresh(argument, argument2):
return argument


class error_details():
def __init__(self) -> None:
self.code = None
self.message = ""


class create_auth():
def __init__(self, option={}, init=False) -> None:
self.id = option.get("id")
Expand All @@ -209,6 +215,7 @@ def __init__(self, option={}, init=False) -> None:
self.auth_details = auth_details()
self.profile_directory = option.get("profile_directory", "")
self.active = False
self.errors: list[error_details] = []
valid_counts = ["chatMessagesCount"]
args = [self.username, False, False]
link_info = links(*args).full
Expand Down Expand Up @@ -531,8 +538,8 @@ def set_auth_details(self, option):
f"user_agent required for: {self.auth.auth_details.username}")
exit()
self.auth.auth_details.user_agent = option["user_agent"]
self.auth.auth_details.email = option.get("email","")
self.auth.auth_details.password = option.get("password","")
self.auth.auth_details.email = option.get("email", "")
self.auth.auth_details.password = option.get("password", "")
self.auth.auth_details.support_2fa = option["support_2fa"]
self.auth.auth_details.active = option["active"]

Expand Down Expand Up @@ -562,22 +569,14 @@ def login(self, full=False, max_attempts=10) -> Union[create_auth, None]:
while count < max_attempts+1:
string = f"Auth {auth_version} Attempt {count}/{max_attempts}"
print(string)
me_api = self.get_authed()
self.get_authed()
count += 1
if me_api and not "error" in me_api:
me_api = create_auth(me_api)
me_api.active = True

def resolve_auth(r):
if 'error' in r:
error = r["error"]
error_message = r["error"]["message"]
error_code = error["code"]
if error_code == 0:
print(error_message)
if error_code == 101:
error_message = "Blocked by 2FA."
print(error_message)

def resolve_auth(auth: create_auth):
if self.auth.errors:
error = self.auth.errors[-1]
print(error.message)
if error.code == 101:
if auth_items.support_2fa:
link = f"https://onlyfans.com/api2/v2/users/otp/check"
count = 1
Expand All @@ -590,41 +589,58 @@ def resolve_auth(r):
r = api_helper.json_request(link,
self.session_manager.sessions[0], method="POST", data=data)
if "error" in r:
error.message = r["error"]["message"]
count += 1
else:
print("Success")
return [True, r]
return [False, r["error"]["message"]]
if not isinstance(me_api, create_auth) and "error" in me_api:
result = resolve_auth(me_api)
if not result[0]:
error_message = result[1]
if "token" in error_message:
break
if "Code wrong" in error_message:
break
continue
else:
continue
print(f"Welcome {me_api.name} | {me_api.username}")
me_api.auth_details = self.auth.auth_details
self.auth = me_api
return self.auth
auth.active = True
auth.errors.remove(error)
break
resolve_auth(self.auth)
if self.auth.errors:
error = self.auth.errors[-1]
error_message = error.message
if "token" in error_message:
break
if "Code wrong" in error_message:
break
continue
else:
print(f"Welcome {self.auth.name} | {self.auth.username}")
return self.auth

def get_authed(self):
def get_authed(self) -> Union[create_auth]:
if not self.auth.active:
link = links().customer
r = api_helper.json_request(
link, self.session_manager.sessions[0], sleep=False)
if r:
r["session_manager"] = self.session_manager
else:
r = self.auth
return r
self.resolve_auth_errors(r)
if not self.auth.errors:
me_api = create_auth(r)
me_api.active = True
me_api.session_manager = self.session_manager
self.auth = me_api
return self.auth

def set_auth(self, me):
self.auth = me

def resolve_auth_errors(self, r):
# Adds an error object to self.auth.errors
if 'error' in r:
error = r["error"]
error_message = r["error"]["message"]
error_code = error["code"]
error = error_details()
if error_code == 0:
pass
if error_code == 101:
error_message = "Blocked by 2FA."
error.code = error_code
error.message = error_message
self.auth.errors.append(error)

def get_user(self, identifier):
link = links(identifier).users
session = self.session_manager.sessions[0]
Expand Down
6 changes: 3 additions & 3 deletions database/models/media_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class media_table():
media_id = sqlalchemy.Column(sqlalchemy.Integer, unique=True)
post_id = sqlalchemy.Column(sqlalchemy.Integer, nullable=False)
link = sqlalchemy.Column(sqlalchemy.String)
directory = sqlalchemy.Column(sqlalchemy.String)
filename = sqlalchemy.Column(sqlalchemy.String)
directory = cast(str,sqlalchemy.Column(sqlalchemy.String))
filename = cast(str,sqlalchemy.Column(sqlalchemy.String))
size = sqlalchemy.Column(sqlalchemy.Integer, default=None)
media_type = sqlalchemy.Column(sqlalchemy.String)
preview = sqlalchemy.Column(sqlalchemy.Integer, default=0)
linked = sqlalchemy.Column(sqlalchemy.String, default=None)
downloaded = sqlalchemy.Column(sqlalchemy.Integer, default=0)
downloaded = cast(bool,sqlalchemy.Column(sqlalchemy.Integer, default=0))
created_at = cast(datetime,sqlalchemy.Column(sqlalchemy.TIMESTAMP))

def legacy(self,Base):
Expand Down
2 changes: 1 addition & 1 deletion datascraper/main_datascraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# return text


def start_datascraper(json_config, site_name_lower, apis: list = [], webhooks=True):
def start_datascraper(json_config:dict, site_name_lower:str, apis: list = [], webhooks=True):
json_settings = json_config["settings"]
json_webhooks = json_settings["webhooks"]
json_sites = json_config["supported"]
Expand Down

0 comments on commit 87237e2

Please sign in to comment.