remove#2105
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the US HUD income script to support processing data up to the current year and introduces validation configurations along with golden datasets for both the US HUD income and FAO currency statvar imports. A review comment points out that using requests.get with stream=True to check the availability of the current year's HUD data can cause connection leaks and is inefficient, suggesting the use of requests.head instead.
| if year == today.year: | ||
| try: | ||
| headers = { | ||
| 'User-Agent': | ||
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' | ||
| } | ||
| resp = requests.get(url, headers=headers, timeout=10, stream=True) | ||
| if resp.status_code != 200: | ||
| logging.warning(f"HUD income limits for {year} are not yet available. Skipping.") | ||
| continue | ||
| except Exception as e: | ||
| logging.warning(f"Could not check availability for {year}: {e}. Skipping.") | ||
| continue |
There was a problem hiding this comment.
Using requests.get with stream=True without closing the response or reading its content causes a connection leak because the connection is not released back to the pool. Additionally, downloading the entire response body just to check the status code is inefficient. Using a HEAD request via requests.head is much more efficient and avoids connection leaks as it only retrieves the headers.
| if year == today.year: | |
| try: | |
| headers = { | |
| 'User-Agent': | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' | |
| } | |
| resp = requests.get(url, headers=headers, timeout=10, stream=True) | |
| if resp.status_code != 200: | |
| logging.warning(f"HUD income limits for {year} are not yet available. Skipping.") | |
| continue | |
| except Exception as e: | |
| logging.warning(f"Could not check availability for {year}: {e}. Skipping.") | |
| continue | |
| if year == today.year: | |
| try: | |
| headers = { | |
| 'User-Agent': | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' | |
| } | |
| resp = requests.head(url, headers=headers, timeout=10) | |
| if resp.status_code != 200: | |
| logging.warning(f'HUD income limits for {year} are not yet available. Skipping.') | |
| continue | |
| except Exception as e: | |
| logging.warning(f'Could not check availability for {year}: {e}. Skipping.') | |
| continue |
Adding golden files for fao_currency_statvar