本文整理汇总了Python中pycurl.PROXY属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.PROXY属性的具体用法?Python pycurl.PROXY怎么用?Python pycurl.PROXY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pycurl
的用法示例。
在下文中一共展示了pycurl.PROXY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def query(url):
"""
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
output = StringIO.StringIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
query.setopt(pycurl.PROXY, 'localhost')
query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.CONNECTTIMEOUT, CONNECTION_TIMEOUT)
query.setopt(pycurl.WRITEFUNCTION, output.write)
try:
query.perform()
return output.getvalue()
except pycurl.error as exc:
raise ValueError("Unable to reach %s (%s)" % (url, exc))
示例2: query
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def query(url):
"""
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
output = io.BytesIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
query.setopt(pycurl.PROXY, 'localhost')
query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.WRITEFUNCTION, output.write)
try:
query.perform()
return output.getvalue()
except pycurl.error as exc:
return "Unable to reach %s (%s)" % (url, exc)
# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running.
示例3: _check_status
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def _check_status(self):
"""
For internal use only. Only members of :class:`Tunnel`
"""
try:
output = io.BytesIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, "%s:%s" % (self.addr, self.status_server.port))
query.setopt(pycurl.PROXY, "127.0.0.1")
query.setopt(pycurl.PROXYPORT, config.tor_proxy_port)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.WRITEFUNCTION, output.write)
query.perform()
return "ONIONGROK_CLIENT_STATUS_SUCCESS" in output.getvalue().decode("utf8")
except Exception as e:
return False
示例4: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
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)]
示例5: _set_common
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def _set_common(self, c):
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.AUTOREFERER, 1)
c.setopt(pycurl.ENCODING, self._accept_encoding)
c.setopt(pycurl.MAXREDIRS, 255)
c.setopt(pycurl.CONNECTTIMEOUT, 30)
c.setopt(pycurl.TIMEOUT, 300)
c.setopt(pycurl.NOSIGNAL, 1)
if self._proxy:
c.setopt(pycurl.PROXY, self._proxy)
if self._url.scheme == 'https':
c.setopt(pycurl.SSLVERSION, 3)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
示例6: test_pycurl_proxy
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def test_pycurl_proxy(self):
"""If provided, the proxy is set in the request."""
curl = CurlStub(b"result")
proxy = "http://my.little.proxy"
result = fetch("http://example.com", curl=curl, proxy=proxy)
self.assertEqual(b"result", result)
self.assertEqual(proxy.encode('ascii'), curl.options[pycurl.PROXY])
示例7: setUrl
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def setUrl(self, urltmp):
self.__variablesGET = VariablesSet()
self.schema, self.__host, self.__path, self.__params, variables, f = urlparse(urltmp)
if "Host" not in self._headers or (not self._headers["Host"]):
self._headers["Host"] = self.__host
if variables:
self.__variablesGET.parseUrlEncoded(variables)
# ############## PROXY ##################################
示例8: _set_extra_options
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def _set_extra_options(self, c, fuzzres, poolid):
if self.pool_map[poolid]["proxy"]:
ip, port, ptype = next(self.pool_map[poolid]["proxy"])
fuzzres.history.wf_proxy = (("%s:%s" % (ip, port)), ptype)
if ptype == "SOCKS5":
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5)
elif ptype == "SOCKS4":
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS4)
elif ptype == "HTTP":
c.setopt(pycurl.PROXY, "%s:%s" % (ip, port))
else:
raise FuzzExceptBadOptions("Bad proxy type specified, correct values are HTTP, SOCKS4 or SOCKS5.")
else:
c.setopt(pycurl.PROXY, "")
mdelay = self.options.get("req_delay")
if mdelay is not None:
c.setopt(pycurl.TIMEOUT, mdelay)
cdelay = self.options.get("conn_delay")
if cdelay is not None:
c.setopt(pycurl.CONNECTTIMEOUT, cdelay)
return c
示例9: run
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def run(self):
with open(self.dst_path_, 'w+b') as fh:
c = pycurl.Curl()
c.setopt(pycurl.URL, self.src_url_)
c.setopt(c.WRITEDATA, fh)
if self.socks_ip_ and self.socks_port_:
c.setopt(pycurl.PROXY, self.socks_ip_)
c.setopt(pycurl.PROXYPORT, self.socks_port_)
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS4)
c.perform()
return self.dst_path_
示例10: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def request(self, url, method, body, headers):
c = pycurl.Curl()
c.setopt(pycurl.URL, str(url))
if 'proxy_host' in self.proxy:
c.setopt(pycurl.PROXY, self.proxy['proxy_host'])
if 'proxy_port' in self.proxy:
c.setopt(pycurl.PROXYPORT, self.proxy['proxy_port'])
if 'proxy_user' in self.proxy:
c.setopt(pycurl.PROXYUSERPWD, "%(proxy_user)s:%(proxy_pass)s" % self.proxy)
self.buf = StringIO()
c.setopt(pycurl.WRITEFUNCTION, self.buf.write)
#c.setopt(pycurl.READFUNCTION, self.read)
#self.body = StringIO(body)
#c.setopt(pycurl.HEADERFUNCTION, self.header)
if self.cacert:
c.setopt(c.CAINFO, str(self.cacert))
c.setopt(pycurl.SSL_VERIFYPEER, self.cacert and 1 or 0)
c.setopt(pycurl.SSL_VERIFYHOST, self.cacert and 2 or 0)
c.setopt(pycurl.CONNECTTIMEOUT, self.timeout/6)
c.setopt(pycurl.TIMEOUT, self.timeout)
if method=='POST':
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, body)
if headers:
hdrs = ['%s: %s' % (str(k), str(v)) for k, v in headers.items()]
##print hdrs
c.setopt(pycurl.HTTPHEADER, hdrs)
c.perform()
##print "pycurl perform..."
c.close()
return {}, self.buf.getvalue()
示例11: setUrl
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def setUrl (self, urltmp):
self.__variablesGET=VariablesSet()
self.schema,self.__host,self.__path,self.__params,variables,f=urlparse(urltmp)
self.__headers["Host"]=self.__host
if variables:
self.__variablesGET.parseUrlEncoded(variables)
############### PROXY ##################################
示例12: get
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
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)
示例13: post
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
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)
示例14: upload
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
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)
示例15: get_rh_sso
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import PROXY [as 别名]
def get_rh_sso(self):
"""
Function wich used login and password to connect at www.redhat.com and return
the "rh_sso" proxy used for request authentication.
"""
self._logger.debug("RHEL rh_sso getting in progress...")
username = self.config_server.redhat["login_username"]
password = self.config_server.redhat["login_pass"]
url = 'https://www.redhat.com/wapps/sso/login.html'
values={'username':username,'password':password,'_flowId':'legacy-login-flow','redirect':'https://www.redhat.com/wapps/ugc/protected/account.html','failureRedirect':'http://www.redhat.com/wapps/sso/login.html'}
data_post = urllib.urlencode(values)
headers = Storage()
c = pycurl.Curl()
c.setopt(pycurl.URL, url)
#==============================================================================
# DEBUG comments in order to use the Burp Proxy software
#==============================================================================
#c.setopt(pycurl.PROXY, '127.0.0.1')
#c.setopt(pycurl.PROXYPORT, 8080)
#c.setopt(pycurl.SSL_VERIFYPEER, 1)
#c.setopt(pycurl.SSL_VERIFYHOST, 2)
#c.setopt(pycurl.CAINFO, "/home/thierry/Divers/Burp/cacert.crt")
#==============================================================================
c.setopt(pycurl.USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0")
c.setopt(pycurl.HTTPHEADER, ['Accept-Language: en-US,en;q=0.5',
'Connection: keep-alive',
'www.whitehouse.gov: 200'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data_post)
c.setopt(c.HEADERFUNCTION, headers.store)
c.perform()
c.close()
headers = str(headers)
expression = r"(?P<var1>.*)(?P<rh_sso>Set-Cookie: rh_sso=)(?P<sso_key>(?!\").*?)(?P<end>;)"
header_lines = headers.split('\n')
for head in header_lines:
result_re = re.match(expression, head)
if result_re is not None:
sso_key = "rh_sso=" + str(result_re.group('sso_key'))
self._logger.debug("rh_sso value : "+ str(sso_key))
return sso_key