Advertisement
alperiox

get() function

Oct 1st, 2022
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | Source Code | 0 0
  1. def get(url, proxy):
  2.     """
  3.    Sends a GET request to the given url using given proxy server.
  4.    The proxy server is used without SSL, so the URL should be HTTP.
  5.  
  6.    Args:
  7.        url - string: HTTP URL to send the GET request with proxy
  8.        proxy - string: proxy server in the form of {ip}:{port} to use while sending the request
  9.    Returns:
  10.        Response of the server if the request sent successfully. Returns `None` otherwise.
  11.  
  12.    """
  13.     try:
  14.         r = requests.get(url, proxies={"http": f"http://{proxy}"})
  15.         if r.status_code < 400: # client-side and server-side error codes are above 400
  16.             return r
  17.         else:
  18.             print(r.status_code)
  19.     except Exception as e:
  20.         print(e)
  21.    
  22.     return None
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement