Skip to content

Commit

Permalink
Merge pull request InstaPy#2683 from uluQulu/master
Browse files Browse the repository at this point in the history
Fix: convert exception messages into a string before encoding AND some other small fixes
  • Loading branch information
timgrossmann authored Aug 16, 2018
2 parents d2bf9c2 + edd91b4 commit 13318e2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions instapy/commenters_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def extract_post_info(browser):
while (" comments" in comments[1].text):
more_comments += 1
print ("loading more comments.")
load_more_comments_element = browser.find_element_by_xpath("//div/ul/li[2]/a")
load_more_comments_element = browser.find_element_by_xpath("//div/ul/li[2]/button")
browser.execute_script("arguments[0].click();", load_more_comments_element)
sleep(1)
#comment_list = post.find_element_by_tag_name('ul')
Expand All @@ -54,7 +54,7 @@ def extract_post_info(browser):
while (" comments" in comments[0].text):
more_comments += 1
print ("loading more comments.")
load_more_comments_element = browser.find_element_by_xpath("//div/ul/li[1]/a")
load_more_comments_element = browser.find_element_by_xpath("//div/ul/li[1]/button")
browser.execute_script("arguments[0].click();", load_more_comments_element)
sleep(1)
#comment_list = post.find_element_by_tag_name('ul')
Expand Down
2 changes: 1 addition & 1 deletion instapy/login_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def login_user(browser,
# Enter username and password and logs the user in
# Sometimes the element name isn't 'Username' and 'Password'
# (valid for placeholder too)
sleep(1)
sleep(2)
input_username = browser.find_elements_by_xpath(
"//input[@name='username']")

Expand Down
28 changes: 14 additions & 14 deletions instapy/relationship_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get_followers(browser,
sc_rolled_all = graphql_queries[username][query_date]["sc_rolled"]

except Exception as exc:
logger.info("Error occured while getting `scroll` data from graphql_queries.json\n{}\n".format(exc.encode("utf-8")))
logger.info("Error occured while getting `scroll` data from graphql_queries.json\n{}\n".format(str(exc).encode("utf-8")))
local_read_failure = True

start_time = time.time()
Expand Down Expand Up @@ -171,7 +171,7 @@ def get_followers(browser,
json.dump(graphql_queries, graphql_queries_file)
except Exception as exc:
print('\n')
logger.info("Error occured while writing `scroll` data to graphql_queries.json\n{}\n".format(exc.encode("utf-8")))
logger.info("Error occured while writing `scroll` data to graphql_queries.json\n{}\n".format(str(exc).encode("utf-8")))

#take breaks gradually
if sc_rolled > 91:
Expand All @@ -182,7 +182,7 @@ def get_followers(browser,

except BaseException as exc:
print('\n')
logger.info("Unable to get `Followers` data:\n\t{}\n".format(exc.encode("utf-8")))
logger.info("Unable to get `Followers` data:\n\t{}\n".format(str(exc).encode("utf-8")))

#remove possible duplicates
all_followers = sorted(set(all_followers), key=lambda x:all_followers.index(x))
Expand Down Expand Up @@ -301,7 +301,7 @@ def get_following(browser,
graphql_queries[username][query_date] = {"sc_rolled":0}
sc_rolled_all = graphql_queries[username][query_date]["sc_rolled"]
except Exception as exc:
logger.info("Error occured while getting `scroll` data from graphql_queries.json\n{}\n".format(exc.encode("utf-8")))
logger.info("Error occured while getting `scroll` data from graphql_queries.json\n{}\n".format(str(exc).encode("utf-8")))
local_read_failure = True

start_time = time.time()
Expand Down Expand Up @@ -369,7 +369,7 @@ def get_following(browser,
json.dump(graphql_queries, graphql_queries_file)
except Exception as exc:
print('\n')
logger.info("Error occured while writing `scroll` data to graphql_queries.json\n{}\n".format(exc.encode("utf-8")))
logger.info("Error occured while writing `scroll` data to graphql_queries.json\n{}\n".format(str(exc).encode("utf-8")))

#take breaks gradually
if sc_rolled > 91:
Expand All @@ -380,7 +380,7 @@ def get_following(browser,

except BaseException as exc:
print('\n')
logger.info("Unable to get `Following` data:\n\t{}\n".format(exc.encode("utf-8")))
logger.info("Unable to get `Following` data:\n\t{}\n".format(str(exc).encode("utf-8")))

#remove possible duplicates
all_following = sorted(set(all_following), key=lambda x:all_following.index(x))
Expand Down Expand Up @@ -665,7 +665,7 @@ def store_followers_data(username, grab, grabbed_followers, logger, logfolder):
logger.info("Stored `Followers` data at {} local file".format(final_file))

except Exception as exc:
logger.info("Failed to store `Followers` data in a local file :Z\n{}".format(exc.encode("utf-8")))
logger.info("Failed to store `Followers` data in a local file :Z\n{}".format(str(exc).encode("utf-8")))


def store_following_data(username, grab, grabbed_following, logger, logfolder):
Expand All @@ -691,7 +691,7 @@ def store_following_data(username, grab, grabbed_following, logger, logfolder):
logger.info("Stored `Following` data at {} local file".format(final_file))

except Exception as exc:
logger.info("Failed to store `Following` data in a local file :Z\n{}".format(exc.encode("utf-8")))
logger.info("Failed to store `Following` data in a local file :Z\n{}".format(str(exc).encode("utf-8")))


def store_all_unfollowers(username, all_unfollowers, logger, logfolder):
Expand All @@ -717,7 +717,7 @@ def store_all_unfollowers(username, all_unfollowers, logger, logfolder):
logger.info("Stored all Unfollowers data at {} local file\n".format(final_file))

except Exception as exc:
logger.info("Failed to store all Unfollowers data in a local file :Z\n{}\n".format(exc.encode("utf-8")))
logger.info("Failed to store all Unfollowers data in a local file :Z\n{}\n".format(str(exc).encode("utf-8")))


def store_active_unfollowers(username, active_unfollowers, logger, logfolder):
Expand All @@ -743,7 +743,7 @@ def store_active_unfollowers(username, active_unfollowers, logger, logfolder):
logger.info("Stored active Unfollowers data at {} local file\n".format(final_file))

except Exception as exc:
logger.info("Failed to store active Unfollowers data in a local file :Z\n{}\n".format(exc.encode("utf-8")))
logger.info("Failed to store active Unfollowers data in a local file :Z\n{}\n".format(str(exc).encode("utf-8")))


def store_nonfollowers(username, followers_size, following_size, nonfollowers, logger, logfolder):
Expand All @@ -770,7 +770,7 @@ def store_nonfollowers(username, followers_size, following_size, nonfollowers, l
logger.info("Stored Nonfollowers data at {} local file\n".format(final_file))

except Exception as exc:
logger.info("Failed to store Nonfollowers data in a local file :Z\n{}\n".format(exc.encode("utf-8")))
logger.info("Failed to store Nonfollowers data in a local file :Z\n{}\n".format(str(exc).encode("utf-8")))


def store_fans(username, followers_size, following_size, fans, logger, logfolder):
Expand Down Expand Up @@ -799,7 +799,7 @@ def store_fans(username, followers_size, following_size, fans, logger, logfolder
logger.info("Stored Fans data at {} local file\n".format(final_file))

except Exception as exc:
logger.info("Failed to store Fans data in a local file :Z\n{}\n".format(exc.encode("utf-8")))
logger.info("Failed to store Fans data in a local file :Z\n{}\n".format(str(exc).encode("utf-8")))


def store_mutual_following(username, followers_size, following_size, mutual_following, logger, logfolder):
Expand Down Expand Up @@ -828,7 +828,7 @@ def store_mutual_following(username, followers_size, following_size, mutual_foll
logger.info("Stored Mutual Following data at {} local file\n".format(final_file))

except Exception as exc:
logger.info("Failed to store Mutual Following data in a local file :Z\n{}\n".format(exc.encode("utf-8")))
logger.info("Failed to store Mutual Following data in a local file :Z\n{}\n".format(str(exc).encode("utf-8")))


def load_followers_data(username, compare_by, compare_track, logger, logfolder):
Expand Down Expand Up @@ -992,6 +992,6 @@ def progress_tracker(current_value, highest_value, initial_time, logger):
sys.stdout.flush()

except Exception as exc:
logger.info("Error occured with Progress Tracker:\n{}".format(exc))
logger.info("Error occured with Progress Tracker:\n{}".format(str(exc).encode("utf-8")))


2 changes: 1 addition & 1 deletion instapy/unfollow_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def unfollow(browser,
continue

except Exception as exc:
logger.error("Unfollow loop error:\n\n{}\n\n".format(exc.encode('utf-8')))
logger.error("Unfollow loop error:\n\n{}\n\n".format(str(exc).encode('utf-8')))

else:
logger.info("Please select a proper unfollow method! ~leaving unfollow activity\n")
Expand Down

0 comments on commit 13318e2

Please sign in to comment.