Esempio n. 1
0
    def __login(self):
        """ Attempt to login to Letterboxd.
        If result is not successful, attempt to return the error
        displayed by the webpage """

        response = self.request("POST", suburl="/user/login.do", data=self.login_details)
        soup = make_soup(response)
        text = soup.text

        result_pattern = r"\"result\": \"(\w+)\""
        result = re.findall(result_pattern, text)[0]

        if result == "success":
            # Login successful
            print(f"Login successful! Welcome, {self.username}")
            return True

        error_msg_pattern = r"\"messages\": \[([^\]]+)"
        try:
            # Try to find specific error in HTML
            error = re.findall(error_msg_pattern, text)[0]
        except IndexError:
            # Could not find specific error
            raise LoginException("Unknown Exception")
        else:
            raise LoginException(error)
Esempio n. 2
0
def login(username, password):
    response = login_simple(username, password)

    # raise errors
    if response.status_code != 200:
        raise LoginException(f'LoginError: ' + response.status_code)
    r_json = response.json()
    if r_json['code'] != 0:
        cprint(r_json['message'], color='red')
        cprint('登录失败(返回值非0)', color='red')
        cprint('解决方法:重启程序再试(建议仅重试一次)', color='green')
        raise LoginException(f'LoginError')

    # handle cookies
    cookies = {}
    cookie_source = [cookie for cookie in r_json['data']['cookie_info']['cookies']]
    for cookie in cookie_source:
        cookies[cookie['name']] = cookie['value']

    # handle tokens
    tokens = {}
    token_source = { key:value for key,value in r_json['data']['token_info'].items() } 
    tokens.update(token_source)

    return { 'app': tokens, 'web': cookies, }
Esempio n. 3
0
    def __login(self):
        """ Attempt to login to Best11. """
        try:
            login_request = req_post(s=self,
                                     suburl=self.login_suburl,
                                     data=self.user_details,
                                     save_cache=False)
        except:
            # Was unable to make request
            raise LoginException("Unable to login to Best11")

        # Verify redirected URL is correct (that login successful)
        if not self.__valid_login(login_request):
            raise LoginException(
                f"Incorrect details given: {self.user_details}")
        return True
Esempio n. 4
0
def login(username, password):
    """login icourse163.org by aikecheng account"""
    # pre login for get NTESSTUDYSI Cookie
    retry_request(INDEX_URL, method='GET')

    data = {
        'returnUrl': 'aHR0cDovL3d3dy5pY291cnNlMTYzLm9yZy8=',
        'failUrl': 'aHR0cDovL3d3dy5pY291cnNlMTYzLm9yZy9tZW1iZXIvbG9naW4uaHRtP2VtYWlsRW5jb2RlZD1OVE0xTURNMk5qSTRRSEZ4TG1OdmJRPT0=',
        'savelogin': '******',
        'oauthType': '',
        'username': username,
        'passwd': password
    }
    try:
        resp = sess.post(AKC_LOGIN_URL, data=data, timeout=20)
    except Exception as e:
        raise LoginException('login request error:%s' % e)
    if username not in sess.cookies.get('STUDY_INFO'):
        raise LoginException('login request success, but login cookies not found')
    logger.info('login success...')
Esempio n. 5
0
    def __login(self):
        """ 
        Attempt to login to best11.
        Called by the __call__ func for this class.
        """

        print("login url", self.login_suburl)
        print("login details", self.user_details)

        try:
            login_request = self.request("POST",
                                         suburl=self.login_suburl,
                                         data=self.user_details)
        except:
            # Was unable to make request
            raise LoginException("Unable to login to")

        # Verify logged in by checking redirected URL
        if not self.__valid_login(login_request):
            raise LoginException(
                f"Incorrect details given: {self.user_details}")
        return True
Esempio n. 6
0
def login_by_pincode(name, password, session, server_data, retry_count, proxy):
    post_url = 'http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.18)'

    servertime = server_data["servertime"]
    nonce = server_data['nonce']
    rsakv = server_data["rsakv"]
    pubkey = server_data["pubkey"]
    pcid = server_data['pcid']

    sp = get_password(password, servertime, nonce, pubkey)

    data = {
        'encoding': 'UTF-8',
        'entry': 'weibo',
        'from': '',
        'gateway': '1',
        'nonce': nonce,
        'pagerefer': "",
        'prelt': 67,
        'pwencode': 'rsa2',
        "returntype": "META",
        'rsakv': rsakv,
        'savestate': '7',
        'servertime': servertime,
        'service': 'miniblog',
        'sp': sp,
        'sr': '1920*1080',
        'su': get_encodename(name),
        'useticket': '1',
        'vsnf': '1',
        'url':
        'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',
        'pcid': pcid
    }

    if not YUMDAMA_USERNAME:
        raise LoginException(
            'Login need verfication code, please set your yumdama info in config/spider.yaml'
        )
    img_url = get_pincode_url(pcid)
    pincode_name = get_img(img_url, name, retry_count, proxy)
    verify_code, yundama_obj, cid = code_verificate(YUMDAMA_USERNAME,
                                                    YUMDAMA_PASSWORD,
                                                    pincode_name)
    data['door'] = verify_code
    rs = get_redirect(name, data, post_url, session, proxy)

    os.remove(pincode_name)
    return rs, yundama_obj, cid, session
Esempio n. 7
0
	def login(self):
		if self.token:
			self.logger.info('Already logged in')
			return
			
		if self.proxy_pool != None:
			self.proxy = next(self.proxy_pool)
			self.logger.info(f'Requests with proxy {self.proxy}')

		root = self.api_request(func_name='logIn',
								params=('<username></username>'
										'<password></password>'
										f'<AppId>{self.APP_ID}</AppId>'))
		res = root.find('.//return')
		if res.find('status').text == 'OK':
			self.token = res.find('data').text
			self.logger.info('Logged in successfully')
			return

		self.logger.error('Error logging in')
		raise LoginException()
Esempio n. 8
0
def login_simple(username, password):
    # obtain login key and hash
    response = request_login_key()
    response = response.json()

    if response['code'] != 0:
        raise LoginException(f'LoginError: ' + str(response))

    pem = response['data']['hash']
    key = response['data']['key']
    username, password = encrypt_uname_passwd(key, pem, username, password)

    # login portal
    url = 'https://passport.bilibili.com/api/v3/oauth2/login'
    params = {
            'appkey': Storage.bili['appkey'],
            'channel': 'bili',
            'mobi_app': 'android',
            'platform': 'android',
            'username': username,
            'password': password,
            'ts': str(int(time.time())),
    }
    ## print(f'params: {params}')
    headers = {
            'Content-type': 'application/x-www-form-urlencoded',
            'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
    }
    param_str = utils.parse_param(params)

    # create signature
    signature = utils.calc_param_sign(param_str)
    param_str += '&' + 'sign' + '=' + signature
    ## print(f'url: {url}\nparam: {param_str}\nheaders: {headers}\n')
    r = requests.post(url, headers=headers, data=param_str)
    return r