1. import requests
  2. def batch_header_request(url, headers):
  3. """
  4. Batches request headers for compatibility with older Python versions.
  5. Args:
  6. url (str): The URL to make the request to.
  7. headers (dict): A dictionary of headers to include in the request.
  8. Returns:
  9. requests.Response: The response object from the request.
  10. """
  11. try:
  12. response = requests.get(url, headers=headers) # Use requests.get to make the request
  13. return response
  14. except Exception as e:
  15. print(f"An error occurred: {e}")
  16. return None
  17. if __name__ == '__main__':
  18. # Example Usage
  19. url = "https://httpbin.org/headers" # Example URL
  20. headers = {
  21. "User-Agent": "MyCustomAgent/1.0",
  22. "X-Custom-Header": "MyValue"
  23. }
  24. response = batch_header_request(url, headers)
  25. if response:
  26. print(response.json()) # Print the response as JSON

Add your comment