What would cause requests.get to timeout, when the url works in the browser?
I've seen the response at requests.get returns 403 while the same url works in browser which talks about masking the User-Agent, but my issue is that I get a TimeoutError, not that it's forbidden. I tried it anyway, and it didn't help.
import requests
def onemap_geocode(postalcode):
header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
onemap_request = 'https://developers.onemap.sg/commonapi/search?searchVal=' + str(postalcode) + '&returnGeom=Y&getAddrDetails=N'
print(onemap_request)
response = requests.get(onemap_request,headers=header)
print('response obtained')
response_json = response.json
lat = response_json['results'][0]['LATITUDE']
lon = response_json['results'][0]['LONGITUDE']
return lat + ', ' + lon
onemap_geocode(178880)