URL Fetching with urllib3 PoolManager

  • Share this:

Code introduction


This function uses urllib3's PoolManager to make a GET request to the specified URL and returns the response data. If the request fails, it returns an error message.


Technology Stack : urllib3

Code Type : HTTP request handler

Code Difficulty : Intermediate


                
                    
def fetch_url(url, timeout=10):
    from urllib3 import PoolManager
    try:
        with PoolManager(timeout=timeout) as http:
            response = http.request('GET', url)
            return response.data
    except Exception as e:
        return str(e)                
              
Tags: