requests.request.text - python examples

Here are the examples of the python api requests.request.text taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

3 View Complete Implementation : weibo_login.py
Copyright GNU General Public License v3.0
Author : MiracleYoung
def get_servertime():
    url = 'http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinastOController.preloginCallBack&su=dW5kZWZpbmVk&client=ssologin.js(v1.3.18)&_=1329806375939'
    # 返回出来的是一个Response对象,无法直接获取,text后,可以通过正则匹配到
    # 大概长这样子的:sinastOController.preloginCallBack({"retcode":0,"servertime":1545606770, ...})
    data = requests.request('GET', url).text
    p = re.compile('\((.*)\)')
    try:
        json_data = p.search(data).group(1)
        data = json.loads(json_data)
        servertime = str(data['servertime'])
        nonce = data['nonce']
        return servertime, nonce
    except:
        print('获取 severtime 失败!')
        return None

0 View Complete Implementation : QGroupRepeater.py
Copyright MIT License
Author : BoYanZh
    def getSetu(self):
        res = ""
        if "我的" in self.msg:
            url = "http://boyanzh.xyz:5000/"
            res = requests.request("GET", url).text
        elif re.search(r'他的|她的|它的', self.msg):
            tag = random.choice(
                ['breasts', 'stockings', 'thighhighs', 'cleavage'])
            url = "https://konachan.net/post.json?" + \
                f"tags=stockings&page={random.randint(1, 100)}"
            json = requests.get(url).json()
            urls = [item['file_url'] for item in json if item['rating'] == 's']
            res = random.choice(urls)
        else:
            url = "https://yande.re/post.json?limit=1&" + \
                f"tags=uncensored&page={random.randint(1, 1000)}"
            json = requests.get(url).json()
            res = json[0]['file_url']
        if res:
            self.lastSetuMsgID = self.msgID + 1
            self.lastSetuMsg = self.msg
        return res

0 View Complete Implementation : channel.py
Copyright GNU General Public License v3.0
Author : epinna
    def req(self, injection):

        get_params = deepcopy(self.get_params)
        post_params = deepcopy(self.post_params)
        header_params = deepcopy(self.header_params)
        url_params = self.base_url
        
        # Pick current injection by index
        inj = deepcopy(self.injs[self.inj_idx])
        
        if inj['field'] == 'URL':
            
            position = inj['position']
            
            url_params = self.base_url[:position] + injection + self.base_url[position+1:]
        
        elif inj['field'] == 'POST':
        
            if inj.get('part') == 'param':
                # Inject injection within param
                old_value = post_params[inj.get('param')]
                del post_params[inj.get('param')]
                
                if self.tag in inj.get('param'):
                    new_param = inj.get('param').replace(self.tag, injection)
                else:
                    new_param = injection
                    
                post_params[new_param] = old_value
                
            if inj.get('part') == 'value':
                
                # If injection in value, replace value by index    
                if self.tag in post_params[inj.get('param')][inj.get('idx')]:
                    post_params[inj.get('param')][inj.get('idx')] = post_params[inj.get('param')][inj.get('idx')].replace(self.tag, injection)
                else:
                    post_params[inj.get('param')][inj.get('idx')] = injection

        elif inj['field'] == 'GET':
                
            if inj.get('part') == 'param':
                # If injection replaces param, save the value 
                # with a new param
                old_value = get_params[inj.get('param')]
                del get_params[inj.get('param')]
                
                if self.tag in inj.get('param'):
                    new_param = inj.get('param').replace(self.tag, injection)
                else:
                    new_param = injection
                    
                get_params[new_param] = old_value
                
            if inj.get('part') == 'value':
                # If injection in value, inject value in the correct index
                if self.tag in get_params[inj.get('param')][inj.get('idx')]:
                    get_params[inj.get('param')][inj.get('idx')] = get_params[inj.get('param')][inj.get('idx')].replace(self.tag, injection)
                else:
                    get_params[inj.get('param')][inj.get('idx')] = injection
                
        elif inj['field'] == 'Header':
            
            # Headers can't contain \r or \n, sanitize
            injection = injection.replace('\n', '').replace('\r', '')
                
            if inj.get('part') == 'param':
                # If injection replaces param, save the value 
                # with a new param
                old_value = get_params[inj.get('param')]
                del header_params[inj.get('param')]
                
                if self.tag in inj.get('param'):
                    new_param = inj.get('param').replace(self.tag, injection)
                else:
                    new_param = injection
                    
                header_params[new_param] = old_value                
                            
            if inj.get('part') == 'value':
                # If injection in value, replace value by index    
                
                if self.tag in header_params[inj.get('param')]:
                    header_params[inj.get('param')] = header_params[inj.get('param')].replace(self.tag, injection)
                else:
                    header_params[inj.get('param')] = injection
        
        if self.tag in self.base_url:
            log.debug('[URL] %s' % url_params)
        if get_params:
            log.debug('[GET] %s' % get_params)
        if post_params:
            log.debug('[POST] %s' % post_params)
        if len(header_params) > 1:
            log.debug('[HEDR] %s' % header_params)
        
        try:
            result = requests.request(
                method = self.http_method,
                url = url_params,
                params = get_params,
                data = post_params,
                headers = header_params,
                proxies = self.proxies,
                # By default, SSL check is skipped.
                # TODO: add a -k curl-like option to set this.
                verify = False
                ).text
        except requests.exceptions.ConnectionError as e:
            if e and e[0] and e[0][0] == 'Connection aborted.':
                log.info('Error: connection aborted, bad status line.')
                result = None
            else:
                raise

        if utils.config.log_response:
            log.debug("""< %s""" % (result) )

        return result