Python pycurl.NOBODY Examples
The following are 11
code examples of pycurl.NOBODY().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pycurl
, or try the search function
.
Example #1
Source File: pycurldownload.py From QMusic with GNU Lesser General Public License v2.1 | 6 votes |
def url_check(self, url): '''下载地址检查''' url_info = {} proto = urlparse.urlparse(url)[0] if proto not in VALIDPROTOCOL: print 'Valid protocol should be http or ftp, but % s found < %s >!' % (proto, url) else: ss = StringIO() curl = pycurl.Curl() curl.setopt(pycurl.FOLLOWLOCATION, 1) curl.setopt(pycurl.MAXREDIRS, 5) curl.setopt(pycurl.CONNECTTIMEOUT, 30) curl.setopt(pycurl.TIMEOUT, 300) curl.setopt(pycurl.NOSIGNAL, 1) curl.setopt(pycurl.NOPROGRESS, 1) curl.setopt(pycurl.NOBODY, 1) curl.setopt(pycurl.HEADERFUNCTION, ss.write) curl.setopt(pycurl.URL, url) try: curl.perform() except: pass if curl.errstr() == '' and curl.getinfo(pycurl.RESPONSE_CODE) in STATUS_OK: url_info['url'] = curl.getinfo(pycurl.EFFECTIVE_URL) url_info['file'] = os.path.split(url_info['url'])[1] url_info['size'] = int( curl.getinfo(pycurl.CONTENT_LENGTH_DOWNLOAD)) url_info['partible'] = (ss.getvalue().find('Accept - Ranges') != -1) return url_info
Example #2
Source File: patator_ext.py From project-black with GNU General Public License v2.0 | 6 votes |
def perform_fp(fp, method, url, header='', body=''): #logger.debug('perform: %s' % url) fp.setopt(pycurl.URL, url) if method == 'GET': fp.setopt(pycurl.HTTPGET, 1) elif method == 'POST': fp.setopt(pycurl.POST, 1) fp.setopt(pycurl.POSTFIELDS, body) elif method == 'HEAD': fp.setopt(pycurl.NOBODY, 1) else: fp.setopt(pycurl.CUSTOMREQUEST, method) headers = [h.strip('\r') for h in header.split('\n') if h] fp.setopt(pycurl.HTTPHEADER, headers) fp.perform()
Example #3
Source File: reqresp.py From wfuzz with GNU General Public License v2.0 | 6 votes |
def head(self): conn=pycurl.Curl() conn.setopt(pycurl.SSL_VERIFYPEER,False) conn.setopt(pycurl.SSL_VERIFYHOST,1) conn.setopt(pycurl.URL,self.completeUrl) conn.setopt(pycurl.HEADER, True) # estas dos lineas son las que importan conn.setopt(pycurl.NOBODY, True) # para hacer un pedido HEAD conn.setopt(pycurl.WRITEFUNCTION, self.header_callback) conn.perform() rp=Response() rp.parseResponse(self.__performHead) self.response=rp
Example #4
Source File: patator.py From patator with GNU General Public License v2.0 | 5 votes |
def perform_fp(fp, method, url, header='', body=''): method = 'RDG_OUT_DATA' header += '\nRDG-Connection-Id: {%s}' % uuid.uuid4() # if authentication is successful the gateway server hangs and won't send a body fp.setopt(pycurl.NOBODY, 1) HTTP_fuzz.perform_fp(fp, method, url, header) # }}} # AJP {{{
Example #5
Source File: Request.py From wfuzz with GNU General Public License v2.0 | 5 votes |
def head(self): conn = pycurl.Curl() conn.setopt(pycurl.SSL_VERIFYPEER, False) conn.setopt(pycurl.SSL_VERIFYHOST, 0) conn.setopt(pycurl.URL, self.completeUrl) conn.setopt(pycurl.NOBODY, True) # para hacer un pedido HEAD conn.setopt(pycurl.WRITEFUNCTION, self.header_callback) conn.perform() rp = Response() rp.parseResponse(self.__performHead) self.response = rp
Example #6
Source File: patator_ext.py From project-black with GNU General Public License v2.0 | 5 votes |
def perform_fp(fp, method, url, header='', body=''): method = 'RDG_OUT_DATA' header += '\nRDG-Connection-Id: {%s}' % uuid.uuid4() # if authentication is successful the gateway server hangs and won't send a body fp.setopt(pycurl.NOBODY, 1) HTTP_fuzz.perform_fp(fp, method, url, header) # }}} # AJP {{{
Example #7
Source File: CurlHelper.py From AdvancedDownloader with GNU General Public License v3.0 | 5 votes |
def _follow_location_and_auto_referer(self): self._curl.setopt(pycurl.FOLLOWLOCATION, True) self._curl.setopt(pycurl.AUTOREFERER, True) self._curl.setopt(pycurl.NOBODY, True)
Example #8
Source File: test_bagofrequests.py From pyaem with MIT License | 5 votes |
def test_request_head(self): curl = pycurl.Curl() curl.setopt = MagicMock() curl.perform = MagicMock() curl.getinfo = MagicMock(return_value=200) curl.close = MagicMock() pycurl.Curl = MagicMock(return_value=curl) method = 'head' url = 'http://localhost:4502/.cqactions.html' params = {'foo1': 'bar1', 'foo2': ['bar2a', 'bar2b']} handlers = {200: self._handler_dummy} result = pyaem.bagofrequests.request(method, url, params, handlers) curl.setopt.assert_any_call(pycurl.HEADER, True) curl.setopt.assert_any_call(pycurl.NOBODY, True) curl.setopt.assert_any_call(pycurl.URL, 'http://localhost:4502/.cqactions.html') curl.setopt.assert_any_call(pycurl.FOLLOWLOCATION, 1) curl.setopt.assert_any_call(pycurl.FRESH_CONNECT, 1) # 6 calls including the one with pycurl.WRITEFUNCTION self.assertEqual(curl.setopt.call_count, 6) curl.perform.assert_called_once_with() curl.getinfo.assert_called_once_with(pycurl.HTTP_CODE) curl.close.assert_called_once_with() self.assertEqual(result.is_success(), True) self.assertEqual(result.message, 'some dummy message') self.assertEqual(result.response['request']['method'], 'head') self.assertEqual(result.response['request']['url'], 'http://localhost:4502/.cqactions.html') self.assertEqual(result.response['request']['params'], params)
Example #9
Source File: patator.py From patator with GNU General Public License v2.0 | 4 votes |
def perform_fp(fp, method, url, header='', body=''): #logger.debug('perform: %s' % url) fp.setopt(pycurl.URL, url) if method == 'GET': fp.setopt(pycurl.HTTPGET, 1) elif method == 'POST': fp.setopt(pycurl.POST, 1) fp.setopt(pycurl.POSTFIELDS, body) elif method == 'HEAD': fp.setopt(pycurl.NOBODY, 1) else: fp.setopt(pycurl.CUSTOMREQUEST, method) headers = [h.strip('\r') for h in header.split('\n') if h] fp.setopt(pycurl.HTTPHEADER, headers) fp.perform()
Example #10
Source File: download.py From launcher with GNU General Public License v3.0 | 4 votes |
def run(self): c = pycurl.Curl() c.setopt(pycurl.URL, self.url) c.setopt(pycurl.FOLLOWLOCATION, True) c.setopt(pycurl.MAXREDIRS, 4) #c.setopt(pycurl.NOBODY, 1) c.setopt(c.VERBOSE, True) #c.setopt(pycurl.CONNECTTIMEOUT, 20) if self.useragent: c.setopt(pycurl.USERAGENT, self.useragent) # add cookies, if available if self.cookies: c.setopt(pycurl.COOKIE, self.cookies) #realurl = c.getinfo(pycurl.EFFECTIVE_URL) realurl = self.url print("realurl",realurl) self.filename = realurl.split("/")[-1].strip() c.setopt(pycurl.URL, realurl) c.setopt(pycurl.FOLLOWLOCATION, True) c.setopt(pycurl.NOPROGRESS, False) c.setopt(pycurl.XFERINFOFUNCTION, self.getProgress) c.setopt(pycurl.SSL_VERIFYPEER, False) c.setopt(pycurl.SSL_VERIFYHOST, False) # configure pycurl output file if self.path == False: self.path = os.getcwd() filepath = os.path.join(self.path, self.filename) if os.path.exists(filepath):## remove old file,restart download os.system("rm -rf " + filepath) buffer = StringIO() c.setopt(pycurl.WRITEDATA, buffer) self._dst_path = filepath # add cookies, if available if self.cookies: c.setopt(pycurl.COOKIE, self.cookies) self._stop = False self.progress["stopped"] = False # download file try: c.perform() except pycurl.error, error: errno,errstr = error print("curl error: %s" % errstr) self._errors.append(errstr) self._stop = True self.progress["stopped"] = True self.stop()
Example #11
Source File: bagofrequests.py From pyaem with MIT License | 4 votes |
def request(method, url, params, handlers, **kwargs): """Sends HTTP request to a specified URL. Parameters will be appended to URL automatically on HTTP get method. Response code will then be used to determine which handler should process the response. When response code does not match any handler, an exception will be raised. :param method: HTTP method (post, delete, get) :type method: str :param url: URL to send HTTP request to :type url: str :param params: Request parameters key-value pairs, use array value to represent multi parameters with the same name :type params: dict :param handlers: Response handlers key-value pairs, keys are response http code, values are callback methods :type handlers: dict :returns: PyAemResult -- Result of the request containing status, response http code and body, and request info :raises: PyAemException """ curl = pycurl.Curl() body_io = cStringIO.StringIO() if method == 'post': curl.setopt(pycurl.POST, 1) curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(params, True)) elif method == 'delete': curl.setopt(pycurl.CUSTOMREQUEST, method) elif method == 'head': curl.setopt(pycurl.HEADER, True) curl.setopt(pycurl.NOBODY, True) else: url = '{0}?{1}'.format(url, urllib.urlencode(params, True)) curl.setopt(pycurl.URL, url) curl.setopt(pycurl.FOLLOWLOCATION, 1) curl.setopt(pycurl.FRESH_CONNECT, 1) curl.setopt(pycurl.WRITEFUNCTION, body_io.write) curl.perform() response = { 'http_code': curl.getinfo(pycurl.HTTP_CODE), 'body': body_io.getvalue(), 'request': { 'method': method, 'url': url, 'params': params } } curl.close() if response['http_code'] in handlers: return handlers[response['http_code']](response, **kwargs) else: handle_unexpected(response, **kwargs)