Skip to content
Snippets Groups Projects
setup_proxy.py 809 B
Newer Older
  • Learn to ignore specific revisions
  • Thorge Petersen's avatar
    Thorge Petersen committed
    import urllib.request, urllib.error, urllib.parse
    
    from ckan.common import config
    
    
    def setup_proxy():
        '''
        This function declares that a proxy server shall be used to access the web via
        urllib2. It takes the proxy address from ckan's config file 
        (
            field "ckanext.odsh.download_proxy",
            example: ckanext.odsh.download_proxy = http://1.2.3.4:4123
        )
        '''
    
        proxy_url = config.get('ckanext.odsh.download_proxy', None)
        if proxy_url:
    
    Thorge Petersen's avatar
    Thorge Petersen committed
            proxy = urllib.request.ProxyHandler({'http': proxy_url, 'https': proxy_url})
            opener = urllib.request.build_opener(proxy)
            urllib.request.install_opener(opener)
    
    
    def clear_proxy():
    
    Thorge Petersen's avatar
    Thorge Petersen committed
        proxy = urllib.request.ProxyHandler({})
        opener = urllib.request.build_opener(proxy)
        urllib.request.install_opener(opener)