Retrieve the contents of the hosts file at the URL, then pass it through domain_to_idna(). Parameters are passed to the requests.get() function. Parameters ---------- url : str or bytes URL for the new Request object. params : Dictionary, list of tuples or
(url, params=None, **kwargs)
| 1694 | |
| 1695 | |
| 1696 | def get_file_by_url(url, params=None, **kwargs): |
| 1697 | """ |
| 1698 | Retrieve the contents of the hosts file at the URL, then pass it through domain_to_idna(). |
| 1699 | |
| 1700 | Parameters are passed to the requests.get() function. |
| 1701 | |
| 1702 | Parameters |
| 1703 | ---------- |
| 1704 | url : str or bytes |
| 1705 | URL for the new Request object. |
| 1706 | params : |
| 1707 | Dictionary, list of tuples or bytes to send in the query string for the Request. |
| 1708 | kwargs : |
| 1709 | Optional arguments that request takes. |
| 1710 | |
| 1711 | Returns |
| 1712 | ------- |
| 1713 | url_data : str or None |
| 1714 | The data retrieved at that URL from the file. Returns None if the |
| 1715 | attempted retrieval is unsuccessful. |
| 1716 | """ |
| 1717 | |
| 1718 | try: |
| 1719 | req = requests.get(url=url, params=params, **kwargs) |
| 1720 | except requests.exceptions.RequestException: |
| 1721 | print("Error retrieving data from {}".format(url)) |
| 1722 | return None |
| 1723 | |
| 1724 | req.encoding = req.apparent_encoding |
| 1725 | res_text = "\n".join([domain_to_idna(line) for line in req.text.split("\n")]) |
| 1726 | return res_text |
| 1727 | |
| 1728 | |
| 1729 | def write_data(f, data): |