Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #993 #995

Merged
merged 4 commits into from
Aug 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions PixivBrowserFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,26 @@ def fanbox_is_logged_in(self):
raise Exception("Not logged in to FANBOX")

def updateFanboxCookie(self):
p_req = mechanize.Request("https://www.fanbox.cc/auth/start")
p_req.add_header('Accept', 'application/json, text/plain, */*')
p_req.add_header('Origin', 'https://www.pixiv.net')
p_req.add_header('User-Agent', self._config.useragent)

p_req = mechanize.Request("https://www.fanbox.cc/login?return_to=https%3A%2F%2Fwww.fanbox.cc%2F")
p_req.add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
p_req.add_header('Referer', 'https://www.fanbox.cc')

try:
p_res = self.open_with_retry(p_req)
page = p_res.read().decode("utf-8")
p_res.close()
except BaseException:
PixivHelper.get_logger().error('Error at updateFanboxCookie(): %s', sys.exc_info())
return False

match = re.search(r"(?<=pixivAccount\.postKey\":\").*?(?=\")", page)
if not match:
raise Exception("Could not get pixivAccount.postKey while trying to log into fanbox.cc with given pixiv.net cookie")

data = {"return_to": "https://www.fanbox.cc/auth/start",
"tt": match.group()}

p_req = mechanize.Request("https://accounts.pixiv.net/account-selected", data, method="POST")
try:
p_res = self.open_with_retry(p_req)
parsed = BeautifulSoup(p_res, features="html5lib").decode('utf-8')
Expand Down