import requests


def URL_is_reachable(url, expected_response=200):
    """== Verifies URL Passed in Returns a Given Response Code ==

    - Pass in URL, and optionally an expected response code (if something other than ``200`` is expected).
    - Returns either ``True`` or ``False``.
    
    == Calling ==
    
    | *Args* | ``url`` (str) | Fully-qualified URL (including protocol). |
    | *Args* | ``expected_response`` (int) | _Optional_ return code if other than ``200``. |
    | *Returns*  |  ``boolean``  | Either True or False. |
    | *Raises*  |  exception  | Returns ``False`` on exception. |

    === Example in Robot ===
    
    | ``${is_reachable} =    URL is Reachable   https://www.google.com``
    """
    try:
        req_return = requests.get(url)
        if req_return.status_code == expected_response:
            return True
        else:
            return False
    except:
        return False