示例#1
0
def urllib2x509httpsGet(url, _cert_file, _key_file):
    urllib2.HTTPSHandler.certfile = _cert_file
    urllib2.HTTPSHandler.keyfile = _key_file
    urllib2.HTTPSHandler.strict = None
    opener = urllib2.build_opener()
    urllib2.install_opener(opener)
    f = urllib2.urlopen(url)
    return f.read()
示例#2
0
def httpProxyGet(url, _http_proxy):
    # HTTP + PROXY example
    log.debug('webutils.httpProxyGet(): Begin fetching URL: %s' % url)

    urllib2.HTTPSHandler.certfile = "/home/jhover/.globus/usercert.pem"
    urllib2.HTTPSHandler.keyfile = "/home/jhover/.globus/userkeynopw.pem"
    urllib2.HTTPSHandler.strict = None

    proxyurl = 'http://%s' % _http_proxy
    log.debug('webutils.httpProxyGet(): Adding proxy: %s' % proxyurl)
    proxy_support = urllib2.ProxyHandler({"http": proxyurl})
    log.debug('webutils.httpProxyGet(): making opener')
    opener = urllib2.build_opener(proxy_support)
    log.debug('webutils.httpProxyGet(): installing opener...')
    urllib2.install_opener(opener)
    log.debug('webutils.httpProxyGet(): making Request...')

    req = urllib2.Request(url)
    response = urllib2.urlopen(req).read().strip()
    return response
示例#3
0
def httpsProxyGet(url, _cert_file, _key_file, _http_proxy):
    # HTTPS + PROXY example
    #import urllib2
    log.debug('webutils.httpsProxyGet(): Begin fetching URL: %s' % url)
    from mariachi.ProxyHTTPConnection import ConnectHTTPSHandler, ConnectHTTPHandler

    urllib2.HTTPSHandler.certfile = _cert_file
    urllib2.HTTPSHandler.keyfile = _key_file
    urllib2.HTTPSHandler.strict = None

    proxyurl = 'http://%s' % _http_proxy
    log.debug('webutils.httpsProxyGet(): Adding proxy: %s' % proxyurl)
    proxy_support = urllib2.ProxyHandler({"http": proxyurl})
    log.debug('webutils.httpsProxyGet(): making opener')
    opener = urllib2.build_opener(proxy_support, ConnectHTTPHandler,
                                  ConnectHTTPSHandler)
    log.debug('webutils.httpsProxyGet(): installing opener...')
    urllib2.install_opener(opener)
    log.debug('webutils.httpsProxyGet(): making Request...')
    req = urllib2.Request(url)
    log.debug('webutils.httpsProxyGet(): calling urlopen(Request)')
    response = urllib2.urlopen(req).read().strip()
    return response
示例#4
0
    def do_open(self, http_class, req):
        log.debug('ConnectHTTPSHandler.do_open():Called... ')
        return urllib2.HTTPSHandler.do_open(self, ProxyHTTPSConnection, req)


if __name__ == '__main__':

    import sys, logging
    # Set up logging.
    logging.basicConfig()
    log.setLevel(logging.DEBUG)
    log.debug("Testing ConnectHTTPHandler")

    test_url = '<URL:https://www-mariachi.physics.sunysb.edu/gridsite/>'
    cert_file = '/home/jhover/.globus/usercert.pem'
    key_file = '/home/jhover/.globus/userkeynopw.pem'

    log.debug('Setting x509. cert=%s, key=%s' % (cert_file, key_file))
    urllib2.HTTPSHandler.certfile = cert_file
    urllib2.HTTPSHandler.keyfile = key_file
    urllib2.HTTPSHandler.strict = None

    log.debug('Building Opener...')
    opener = urllib2.build_opener(ConnectHTTPHandler, ConnectHTTPSHandler)
    urllib2.install_opener(opener)
    req = urllib2.Request(url=test_url)
    req.set_proxy('192.168.1.130:3128', 'https')
    log.debug("Opening url %s" % test_url)
    f = urllib2.urlopen(req)
    print f.read()
示例#5
0
def httpsGet(url):

    response = urllib2.urlopen(url).read().strip()
    return response