Example #1
0
 def login(self, username, password):
     su = base64.b64encode(urllib.quote(username))
     pre_data = self.pre_login(su)
     sp = self.encrypt_password(password, pre_data)
     data = {
         'client': self.JS_CLIENT,
         'entry': 'weibo',
         'gateway': '1',
         'from': '',
         'savestate': '0',
         'userticket': '1',
         'ssosimplelogin': '******',
         'vsnf': '1',
         'vsnval': '',
         'su': su,
         'service': 'miniblog',
         'servertime': pre_data.servertime,
         'nonce': pre_data.nonce,
         'pwencode': 'rsa2',
         'prelt': '164',
         'sp': sp,
         'encoding': 'UTF-8',
         'url':
         'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',
         'returntype': 'META',
         'rsakv': pre_data.rsakv,
     }
     response = self._session.post(self.LOGIN_URL, data=data)
     url = self.URL_REGEX.findall(response.text)[0]
     query = parse_querystring(url)
     if query['retcode'] != '0':
         raise ApiResponseError(response, query['retcode'], query['reason'])
     return self._session.get(url)
Example #2
0
    def get_code(self, username, password, allow_redirects=True):
        data = {
            "client_id": self.app.key,
            "redirect_uri": self.app.redirect_uri,
            "userId": username,
            "passwd": password,
            "isLoginSina": "0",
            "action": "submit",
            "response_type": "code",
        }

        headers = {
            "User-Agent":
            "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36",
            "Host": "api.weibo.com",
            "Referer": self.authorize()
        }

        r = self._session.post(self.AUTH_URL,
                               data=data,
                               headers=headers,
                               allow_redirects=allow_redirects)
        if allow_redirects:
            code_url = r.url
        else:
            code_url = r.headers['location']
        query = parse_querystring(code_url)
        return query['code']
Example #3
0
File: web.py Project: CCPLab/PsyMap
 def login(self, username, password):
     su = base64.b64encode(urllib.quote(username))
     pre_data = self.pre_login(su)
     sp = self.encrypt_password(password, pre_data)
     data = {
         'client': self.JS_CLIENT,
         'entry': 'weibo',
         'gateway': '1',
         'from': '',
         'savestate': '0',
         'userticket': '1',
         'ssosimplelogin': '******',
         'vsnf': '1',
         'vsnval': '',
         'su': su,
         'service': 'miniblog',
         'servertime': pre_data.servertime,
         'nonce': pre_data.nonce,
         'pwencode': 'rsa2',
         'prelt': '164',
         'sp': sp,
         'encoding': 'UTF-8',
         'url': 'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',
         'returntype': 'META',
         'rsakv': pre_data.rsakv,
     }
     response = self._session.post(self.LOGIN_URL, data=data)
     url = self.URL_REGEX.findall(response.text)[0]
     query = parse_querystring(url)
     if query['retcode'] != '0':
         raise ApiResponseError(response, query['retcode'], query['reason'])
     return self._session.get(url)
Example #4
0
    def get_code(self, username, password, allow_redirects=True):
        data = {"client_id": self.app.key,
                "redirect_uri": self.app.redirect_uri,
                "userId": username,
                "passwd": password,
                "isLoginSina": "0",
                "action": "submit",
                "response_type": "code",
        }

        headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36",
            "Host": "api.weibo.com",
            "Referer": self.authorize()
        }

        r = self._session.post(self.AUTH_URL, data=data, headers=headers, allow_redirects=allow_redirects)
        if allow_redirects:
            code_url = r.url
        else:
            code_url = r.headers['location']
        query = parse_querystring(code_url)
        return query['code']
Example #5
0
 def _parse_token(self, response):
     data = parse_querystring(response.text)
     if 'errorCode' in data:
         raise ApiResponseError(response, data['errorCode'], data.get('errorMsg', '').strip("'"))
     return Token(**data)
Example #6
0
 def decode_parameters(top_parameters):
     """  将top_parameters字符串解码并转换为字典,(已测试成功,不要更改)
     """
     parameters = base64.decodestring(unquote(top_parameters))
     return parse_querystring(parameters)