Plain HTTP API call to Google Geocoding API fails with Python requests module
Question: I'm inside a corporate proxy, so often I have SSL issues and have to fall back
to plain HTTP (when it's not an issue involving sensitive data). Thus, I'm
trying to geotag with [Google's Geocoding
API](https://developers.google.com/maps/documentation/geocoding) over plain
HTTP. When I craft a call and execute it with `curl` on the terminal, I get my
JSON resonse as expected. But, when I put the same URL inside a Python script
and hit the URL with `requests.get`, I get an SSL error:

    
    
    {u'status': u'REQUEST_DENIED', u'error_message': u'Requests to this API must be over SSL.', u'results': []}
    

The Python is dead-simple, but here it is for posterity:

    
    
    import json
    import requests
    
    response = requests.get('http://maps.googleapis.com/maps/api/geocode/json?address=some+address+here&key=my-key')
    json_data = json.loads(response.text)
    
    print json_data
    

And, of course, if I try the call with HTTPS I run in to proxy cert errors.
Any ideas?

* * *

UPDATE:

I know I can add the `verify=false` flag to the `requests` method call to
overcome the SSL cert issue, but that doesn't help me understand why the call
is bouncing off the API even though it ostensibly accepts plain HTTP calls.


Answer: You should use the http**s** protocol for your request

    
    
    import json
    import requests
    
    response = requests.get('https://maps.googleapis.com/maps/api/geocode/json?address=some+address+here&key=my-key')
    json_data = json.loads(response.text)
    
    print json_data
    

The example url from the Google
[documentation](https://developers.google.com/maps/documentation/geolocation/intro):
[https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=my_key](https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=my_key)

gives

> {u'status': u'OK', u'results': [{u'geometry': {u'location': {u'lat':
> 37.422245, u'lng': -122.0840084}, u'viewport': {u'northeast': {u'lat':
> 37.42359398029149, u'lng': -122.0826594197085}, u'southwest': {u'lat':
> 37.4208960197085, u'lng': -122.0853573802915}}, u'location_type':
> u'ROOFTOP'}, u'address_components': [{u'long_name': u'1600', u'types':
> [u'street_number'], u'short_name': u'1600'}, {u'long_name': u'Amphitheatre
> Parkway', u'types': [u'route'], u'short_name': u'Amphitheatre Pkwy'},
> {u'long_name': u'Mountain View', u'types': [u'locality', u'political'],
> u'short_name': u'Mountain View'}, {u'long_name': u'Santa Clara County',
> u'types': [u'administrative_area_level_2', u'political'], u'short_name':
> u'Santa Clara County'}, {u'long_name': u'California', u'types':
> [u'administrative_area_level_1', u'political'], u'short_name': u'CA'},
> {u'long_name': u'United States', u'types': [u'country', u'political'],
> u'short_name': u'US'}, {u'long_name': u'94043', u'types': [u'postal_code'],
> u'short_name': u'94043'}], u'place_id': u'ChIJ2eUgeAK6j4ARbn5u_wAGqWA',
> u'formatted_address': u'1600 Amphitheatre Pkwy, Mountain View, CA 94043,
> USA', u'types': [u'street_address']}]}

