Skip to content

Commit

Permalink
added user-agent to requests.get calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dwillis committed Dec 22, 2022
1 parent 1742365 commit f70620d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions clarify/jurisdiction.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_current_ver(cls, election_url):
if ret == None:
election_url_parts = election_url_parts._replace(path=base_uri + filename)
current_ver_url = parse.urlunsplit(election_url_parts)
current_ver_response = requests.get(current_ver_url)
current_ver_response = requests.get(current_ver_url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})
try:
current_ver_response.raise_for_status()
ret = current_ver_response.text
Expand Down Expand Up @@ -126,7 +126,7 @@ def get_latest_summary_url(cls, election_url):

latest_summary_url = parse.urlunsplit(latest_summary_url_parts)

latest_summary_url_response = requests.get(latest_summary_url)
latest_summary_url_response = requests.get(latest_summary_url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})

try:
latest_summary_url_response.raise_for_status()
Expand All @@ -149,7 +149,7 @@ def get_subjurisdictions(self):
if 'Web02' in self.url or 'web.' in self.url:
json_url = self.get_latest_summary_url(self.url).replace('summary.json', 'electionsettings.json')
try:
r = requests.get(json_url)
r = requests.get(json_url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})
r.raise_for_status()
jurisdictions = []
counties = r.json()['settings']['electiondetails']['participatingcounties']
Expand All @@ -160,7 +160,7 @@ def get_subjurisdictions(self):
elif not subjurisdictions_url:
json_url = self.url.replace('summary.html', 'json/electionsettings.json')
try:
r = requests.get(json_url)
r = requests.get(json_url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})
r.raise_for_status()
jurisdictions = []
counties = r.json()['settings']['electiondetails']['participatingcounties']
Expand All @@ -169,7 +169,7 @@ def get_subjurisdictions(self):
except requests.exceptions.HTTPError:
json_url = self.url.replace('summary.html', 'json/en/electionsettings.json')
try:
r = requests.get(json_url)
r = requests.get(json_url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})
r.raise_for_status()
jurisdictions = []
counties = r.json()['settings']['electiondetails']['participatingcounties']
Expand All @@ -178,7 +178,7 @@ def get_subjurisdictions(self):
except requests.exceptions.HTTPError:
return []
try:
r = requests.get(subjurisdictions_url)
r = requests.get(subjurisdictions_url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})
r.raise_for_status()

# Use a maximum of 10 workers. Should we parameterize this?
Expand Down Expand Up @@ -298,7 +298,7 @@ def report_url(self, fmt):
Returns link to detailed report depending on format. Formats are xls, txt and xml.
"""
url = self._state_url() + '/' + '/'.join(self.parsed_url.path.split('/')[2:-2]) + "/reports/detail{}.zip".format(fmt)
r = requests.get(url)
r = requests.get(url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})
if r.status_code == 200:
return url
else:
Expand All @@ -309,7 +309,7 @@ def _get_summary_url(self):
Returns the summary report URL for a jurisdiction.
"""
url = self._state_url() + '/' + '/'.join(self.parsed_url.path.split('/')[2:-2]) + "/reports/summary.zip"
r = requests.get(url)
r = requests.get(url, headers={"User-Agent": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"})
if r.status_code == 200:
return url
else:
Expand Down

0 comments on commit f70620d

Please sign in to comment.