Python pycurl.COOKIEFILE Examples
The following are 13
code examples of pycurl.COOKIEFILE().
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: hub.py From robot with MIT License | 6 votes |
def generate_curl(self, url=None, headers=None): """ 生成一个curl, 返回 curl 实例和用于获取结果的 buffer """ curl = pycurl.Curl() buff = StringIO() curl.setopt(pycurl.COOKIEFILE, "cookie") curl.setopt(pycurl.COOKIEJAR, "cookie_jar") curl.setopt(pycurl.SHARE, self.http._share) curl.setopt(pycurl.WRITEFUNCTION, buff.write) curl.setopt(pycurl.FOLLOWLOCATION, 1) curl.setopt(pycurl.MAXREDIRS, 5) curl.setopt(pycurl.TIMEOUT, 3) curl.setopt(pycurl.CONNECTTIMEOUT, 3) if url: curl.setopt(pycurl.URL, url) if headers: self.set_curl_headers(curl, headers) return curl, buff
Example #2
Source File: files.py From docassemble with MIT License | 6 votes |
def fetch_url(self, url, **kwargs): filename = kwargs.get('filename', self.filename) self.fix() cookiefile = tempfile.NamedTemporaryFile(suffix='.txt') f = open(os.path.join(self.directory, filename), 'wb') c = pycurl.Curl() c.setopt(c.URL, url) c.setopt(c.FOLLOWLOCATION, True) c.setopt(c.WRITEDATA, f) c.setopt(pycurl.USERAGENT, 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36') c.setopt(pycurl.COOKIEFILE, cookiefile.name) c.perform() c.close() cookiefile.close() self.save() return
Example #3
Source File: Checkpoint.py From Instagram-API with MIT License | 5 votes |
def request(self, endpoint, headers=None, post=None, first=True): buffer = BytesIO() ch = pycurl.Curl() ch.setopt(pycurl.URL, endpoint) ch.setopt(pycurl.USERAGENT, self.userAgent) ch.setopt(pycurl.WRITEFUNCTION, buffer.write) ch.setopt(pycurl.FOLLOWLOCATION, True) ch.setopt(pycurl.HEADER, True) if headers: ch.setopt(pycurl.HTTPHEADER, headers) ch.setopt(pycurl.VERBOSE, self.debug) ch.setopt(pycurl.SSL_VERIFYPEER, False) ch.setopt(pycurl.SSL_VERIFYHOST, False) ch.setopt(pycurl.COOKIEFILE, self.settingsPath + self.username + '-cookies.dat') ch.setopt(pycurl.COOKIEJAR, self.settingsPath + self.username + '-cookies.dat') if post: import urllib ch.setopt(pycurl.POST, len(post)) ch.setopt(pycurl.POSTFIELDS, urllib.urlencode(post)) ch.perform() resp = buffer.getvalue() header_len = ch.getinfo(pycurl.HEADER_SIZE) header = resp[0: header_len] body = resp[header_len:] ch.close() if self.debug: import urllib print("REQUEST: " + endpoint) if post is not None: if not isinstance(post, list): print('DATA: ' + urllib.unquote_plus(json.dumps(post))) print("RESPONSE: " + body + "\n") return [header, json_decode(body)]
Example #4
Source File: InstagramRegistration.py From Instagram-API with MIT License | 5 votes |
def request(self, endpoint, post=None): buffer = BytesIO() ch = pycurl.Curl() ch.setopt(pycurl.URL, Constants.API_URL + endpoint) ch.setopt(pycurl.USERAGENT, self.userAgent) ch.setopt(pycurl.WRITEFUNCTION, buffer.write) ch.setopt(pycurl.FOLLOWLOCATION, True) ch.setopt(pycurl.HEADER, True) ch.setopt(pycurl.VERBOSE, False) ch.setopt(pycurl.COOKIEFILE, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat")) ch.setopt(pycurl.COOKIEJAR, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat")) if post is not None: ch.setopt(pycurl.POST, True) ch.setopt(pycurl.POSTFIELDS, post) if self.proxy: ch.setopt(pycurl.PROXY, self.proxyHost) if self.proxyAuth: ch.setopt(pycurl.PROXYUSERPWD, self.proxyAuth) ch.perform() resp = buffer.getvalue() header_len = ch.getinfo(pycurl.HEADER_SIZE) header = resp[0: header_len] body = resp[header_len:] ch.close() if self.debug: print("REQUEST: " + endpoint) if post is not None: if not isinstance(post, list): print("DATA: " + str(post)) print("RESPONSE: " + body) return [header, json_decode(body)]
Example #5
Source File: restClient.py From recipebook with MIT License | 5 votes |
def get(url, encoding, user_agent=UA, referrer=None): """Make a GET request of the url using pycurl and return the data (which is None if unsuccessful)""" data = None databuffer = BytesIO() curl = pycurl.Curl() curl.setopt(pycurl.URL, url) curl.setopt(pycurl.FOLLOWLOCATION, 1) curl.setopt(pycurl.CONNECTTIMEOUT, 5) curl.setopt(pycurl.TIMEOUT, 8) curl.setopt(pycurl.WRITEDATA, databuffer) curl.setopt(pycurl.COOKIEFILE, '') if user_agent: curl.setopt(pycurl.USERAGENT, user_agent) if referrer is not None: curl.setopt(pycurl.REFERER, referrer) try: curl.perform() data = databuffer.getvalue().decode(encoding) except Exception: pass curl.close() return data
Example #6
Source File: CleanScraper.py From CleanScrape with MIT License | 5 votes |
def get_url (url, user_agent=UA, referrer=None): """Make a GET request of the url using pycurl and return the data (which is None if unsuccessful)""" data = None databuffer = StringIO() curl = pycurl.Curl() curl.setopt(pycurl.URL, url) curl.setopt(pycurl.FOLLOWLOCATION, 1) curl.setopt(pycurl.CONNECTTIMEOUT, 5) curl.setopt(pycurl.TIMEOUT, 8) curl.setopt(pycurl.WRITEFUNCTION, databuffer.write) curl.setopt(pycurl.COOKIEFILE, '') if user_agent: curl.setopt(pycurl.USERAGENT, user_agent) if referrer is not None: curl.setopt(pycurl.REFERER, referrer) try: curl.perform() data = databuffer.getvalue() except Exception: pass curl.close() return data
Example #7
Source File: tornadohttpclient.py From robot with MIT License | 5 votes |
def setup_curl(self): _curls = [] for curl in self._curls: curl.setopt(pycurl.SHARE, self._share) if self.use_cookie: curl.setopt(pycurl.COOKIEFILE, "cookie") curl.setopt(pycurl.COOKIEJAR, "cookie_jar") _curls.append(curl) self._curls = _curls
Example #8
Source File: core.py From docassemble with MIT License | 5 votes |
def from_url(self, url): """Makes the contents of the file the contents of the given URL.""" self.retrieve() cookiefile = tempfile.NamedTemporaryFile(suffix='.txt') the_path = self.file_info['path'] f = open(the_path, 'wb') c = pycurl.Curl() c.setopt(c.URL, url) c.setopt(c.FOLLOWLOCATION, True) c.setopt(c.WRITEDATA, f) c.setopt(pycurl.USERAGENT, docassemble.base.functions.server.daconfig.get('user agent', 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36')) c.setopt(pycurl.COOKIEFILE, cookiefile.name) c.perform() c.close() self.retrieve()
Example #9
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __init__(self, base_url="", fakeheaders=[]): self.handle = pycurl.Curl() # These members might be set. self.set_url(base_url) self.verbosity = 0 self.fakeheaders = fakeheaders # Nothing past here should be modified by the caller. self.payload = None self.payload_io = BytesIO() self.hrd = "" # Verify that we've got the right site; harmless on a non-SSL connect. self.set_option(pycurl.SSL_VERIFYHOST, 2) # Follow redirects in case it wants to take us to a CGI... self.set_option(pycurl.FOLLOWLOCATION, 1) self.set_option(pycurl.MAXREDIRS, 5) self.set_option(pycurl.NOSIGNAL, 1) # Setting this option with even a nonexistent file makes libcurl # handle cookie capture and playback automatically. self.set_option(pycurl.COOKIEFILE, "/dev/null") # Set timeouts to avoid hanging too long self.set_timeout(30) # Use password identification from .netrc automatically self.set_option(pycurl.NETRC, 1) self.set_option(pycurl.WRITEFUNCTION, self.payload_io.write) def header_callback(x): self.hdr += x.decode('ascii') self.set_option(pycurl.HEADERFUNCTION, header_callback)
Example #10
Source File: utils.py From APIFuzzer with GNU General Public License v3.0 | 4 votes |
def init_pycurl(debug=False): """ Provides an instances of pycurl with basic configuration :return: pycurl instance """ _curl = pycurl.Curl() _curl.setopt(pycurl.SSL_OPTIONS, pycurl.SSLVERSION_TLSv1_2) _curl.setopt(pycurl.SSL_VERIFYPEER, False) _curl.setopt(pycurl.SSL_VERIFYHOST, False) _curl.setopt(pycurl.VERBOSE, debug) _curl.setopt(pycurl.TIMEOUT, 10) _curl.setopt(pycurl.COOKIEFILE, "") _curl.setopt(pycurl.USERAGENT, 'APIFuzzer') return _curl
Example #11
Source File: mycurl.py From QMusic with GNU Lesser General Public License v2.1 | 4 votes |
def get(self, url, header=None, proxy_host=None, proxy_port=None, cookie_file=None): ''' open url width get method @param url: the url to visit @param header: the http header @param proxy_host: the proxy host name @param proxy_port: the proxy port ''' crl = pycurl.Curl() #crl.setopt(pycurl.VERBOSE,1) crl.setopt(pycurl.NOSIGNAL, 1) # set proxy # crl.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5) rel_proxy_host = proxy_host or self.proxy_host if rel_proxy_host: crl.setopt(pycurl.PROXY, rel_proxy_host) rel_proxy_port = proxy_port or self.proxy_port if rel_proxy_port: crl.setopt(pycurl.PROXYPORT, rel_proxy_port) # set cookie rel_cookie_file = cookie_file or self.cookie_file if rel_cookie_file: crl.setopt(pycurl.COOKIEFILE, rel_cookie_file) crl.setopt(pycurl.COOKIEJAR, rel_cookie_file) # set ssl crl.setopt(pycurl.SSL_VERIFYPEER, 0) crl.setopt(pycurl.SSL_VERIFYHOST, 0) crl.setopt(pycurl.SSLVERSION, 3) crl.setopt(pycurl.CONNECTTIMEOUT, 10) crl.setopt(pycurl.TIMEOUT, 300) crl.setopt(pycurl.HTTPPROXYTUNNEL, 1) rel_header = header or self.header if rel_header: crl.setopt(pycurl.HTTPHEADER, rel_header) crl.fp = StringIO.StringIO() if isinstance(url, unicode): url = str(url) crl.setopt(pycurl.URL, url) crl.setopt(crl.WRITEFUNCTION, crl.fp.write) try: crl.perform() except Exception, e: raise CurlException(e)
Example #12
Source File: mycurl.py From QMusic with GNU Lesser General Public License v2.1 | 4 votes |
def post(self, url, data, header=None, proxy_host=None, proxy_port=None, cookie_file=None): ''' open url width post method @param url: the url to visit @param data: the data to post @param header: the http header @param proxy_host: the proxy host name @param proxy_port: the proxy port ''' crl = pycurl.Curl() #crl.setopt(pycurl.VERBOSE,1) crl.setopt(pycurl.NOSIGNAL, 1) # set proxy rel_proxy_host = proxy_host or self.proxy_host if rel_proxy_host: crl.setopt(pycurl.PROXY, rel_proxy_host) rel_proxy_port = proxy_port or self.proxy_port if rel_proxy_port: crl.setopt(pycurl.PROXYPORT, rel_proxy_port) # set cookie rel_cookie_file = cookie_file or self.cookie_file if rel_cookie_file: crl.setopt(pycurl.COOKIEFILE, rel_cookie_file) crl.setopt(pycurl.COOKIEJAR, rel_cookie_file) # set ssl crl.setopt(pycurl.SSL_VERIFYPEER, 0) crl.setopt(pycurl.SSL_VERIFYHOST, 0) crl.setopt(pycurl.SSLVERSION, 3) crl.setopt(pycurl.CONNECTTIMEOUT, 10) crl.setopt(pycurl.TIMEOUT, 300) crl.setopt(pycurl.HTTPPROXYTUNNEL, 1) rel_header = header or self.header if rel_header: crl.setopt(pycurl.HTTPHEADER, rel_header) crl.fp = StringIO.StringIO() crl.setopt(crl.POSTFIELDS, data) # post data if isinstance(url, unicode): url = str(url) crl.setopt(pycurl.URL, url) crl.setopt(crl.WRITEFUNCTION, crl.fp.write) try: crl.perform() except Exception, e: raise CurlException(e)
Example #13
Source File: mycurl.py From QMusic with GNU Lesser General Public License v2.1 | 4 votes |
def upload(self, url, data, header=None, proxy_host=None, proxy_port=None, cookie_file=None): ''' open url with upload @param url: the url to visit @param data: the data to upload @param header: the http header @param proxy_host: the proxy host name @param proxy_port: the proxy port ''' crl = pycurl.Curl() #crl.setopt(pycurl.VERBOSE,1) crl.setopt(pycurl.NOSIGNAL, 1) # set proxy rel_proxy_host = proxy_host or self.proxy_host if rel_proxy_host: crl.setopt(pycurl.PROXY, rel_proxy_host) rel_proxy_port = proxy_port or self.proxy_port if rel_proxy_port: crl.setopt(pycurl.PROXYPORT, rel_proxy_port) # set cookie rel_cookie_file = cookie_file or self.cookie_file if rel_cookie_file: crl.setopt(pycurl.COOKIEFILE, rel_cookie_file) crl.setopt(pycurl.COOKIEJAR, rel_cookie_file) # set ssl crl.setopt(pycurl.SSL_VERIFYPEER, 0) crl.setopt(pycurl.SSL_VERIFYHOST, 0) crl.setopt(pycurl.SSLVERSION, 3) crl.setopt(pycurl.CONNECTTIMEOUT, 10) crl.setopt(pycurl.TIMEOUT, 300) crl.setopt(pycurl.HTTPPROXYTUNNEL, 1) rel_header = header or self.header if rel_header: crl.setopt(pycurl.HTTPHEADER, rel_header) crl.fp = StringIO.StringIO() if isinstance(url, unicode): url = str(url) crl.setopt(pycurl.URL, url) crl.setopt(pycurl.HTTPPOST, data) # upload file crl.setopt(crl.WRITEFUNCTION, crl.fp.write) try: crl.perform() except Exception, e: raise CurlException(e)