Python: Urllib proxyhandler error
Question: So I'm fairly new to using the urllib.request library and I'm trying to run a
proxy through proxy handler, however I keep getting this error message

    
    
    assert hasattr(proxies, 'keys'), "proxies must be a mapping"
    AssertionError: proxies must be a mapping
    

My code is

    
    
    import urllib.request
    
    proxy = "https://107.170.206.225"
    handler = urllib.request.ProxyHandler(proxy)
    opener = urllib.request.build_opener(handler)
    urllib.request.install_opener(opener)
    response = urllib.request.urlopen('http://youtube.com/')
    

I've tried looking through the documentation and it said to make sure to use
the dictionary mapping protocol but I'm unsure of how to do that so any help
would be appreciated.


Answer: You are right [the documentation for
ProxyHandler](https://docs.python.org/3.0/library/urllib.request.html#urllib.request.ProxyHandler)
says that _"`proxies` must be a dictionary mapping protocol names to URLs of
proxies"_. And it must be read as _"`proxies` must be a dictionary that maps
protocol names to URLs of proxies"_. In your case `proxies` should be defined
as follows.

    
    
    proxies = {'https': '107.170.206.225'}
    handler = urllib.request.ProxyHandler(proxies)
    

