-2

I live in San Diego, and I have been running a little covid dashboard for my neighborhood using the SD County API. Here is the API website: https://sdgis-sandag.opendata.arcgis.com/datasets/covid-19-statistics-by-zip-code/api and here is the query I have been using: https://gis-public.sandiegocounty.gov/arcgis/rest/services/Hosted/COVID_19_Statistics__by_ZIP_Code/FeatureServer/0/query?where=ziptext%20%3D%20%2792131%27&outFields=*&outSR=4326&f=json

Everything was working just fine until the county implemented some kind of firewall to prevent DDOS attacks, and I can no longer access this API. I have a simple python request and it times out: requests.post(srQuery,timeout=5) The employee I have been speaking with doesnt know why its happening and cant seem to fix it.

The only work around I can think of is to use a browser to access the API, and save the file to my computer, and read it in manually. Does anyone have a better idea? Or an idea of how to automate the saving of a browser file to my hard drive?

claudiaann1
  • 237
  • 3
  • 12
  • “*Any comparable package does the same*” Questions seeking recommendations for libraries and other off-site resources are explicitly off-topic here per the scope of the site defined in the [help/on-topic]. – esqew Jan 04 '22 at 00:48
  • 1
    It could be that the site/API is 1) rate-limiting you, in which case try reducing the requests you make and/or following their fair usage policy, or 2) blocking the Python requests library, in which case see [How to use Python requests to fake a browser visit a.k.a and generate User Agent?](https://stackoverflow.com/q/27652543/2745495) – Gino Mempin Jan 04 '22 at 01:04

1 Answers1

1

You need to add User-Agent to your headers in the request.

import requests

headers = {'User-Agent': '[insert user agent here]'}
r = requests.get("https://gis-public.sandiegocounty.gov/arcgis/rest/services/Hosted/COVID_19_Statistics__by_ZIP_Code/FeatureServer/0/query?where=ziptext%20%3D%20%2792131%27&outFields=*&outSR=4326&f=json", headers=headers)
print(r.status_code) # Should not time out. Should return with a status code of 200.
BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33