1

I'm basically doing the following: https://developers.google.com/maps/documentation/business/webservices/auth

In Python 2.7.3 on my MacBook and on 2.7.5 on a Windows 64bit Server environment I fail to reproduce the correct signature, while I follow the original example exactly. I make a function like this:

import sys
import hashlib
import urllib
import hmac
import base64
import urlparse

def process_url(input_url, private_key):
    print("URL To Sign: " + input_url)
    url = urlparse.urlparse(input_url)
    print("Private Key: " + private_key)
    url_to_sign = url.path + "?" + url.query
    print("Original Path + Query: " + url_to_sign)
    decoded_key = base64.urlsafe_b64decode(private_key)
    signature = hmac.new(decoded_key, url_to_sign, hashlib.sha1)
    encodedSignature = base64.urlsafe_b64encode(signature.digest())
    print("B64 Signature: " + encodedSignature)
    original_url = url.scheme + "://" + url.netloc + url.path + "?" + url.query
    full_url = original_url + "&signature=" + encodedSignature
    print "Full URL: " + full_url
    return full_url

Now this should give the following according to google:

However, when I do the following:

process_url('http://maps.googleapis.com/maps/api/geocode/json?address=New+York&sensor=false&client={clientID}', 'vNIXE0xscrmjlyV-12Nj_BvUPaw=')

I get:

So I get "WlcBIkr9WMB9uPhXWmAGcjG_2M4=" and not "KrU1TzVQM7Ur0i8i7K3huiw3MsA=". I swear this used to work, but I get this new W-value consistently over different systems.

Does anyone have any clue what I'm doing wrong? Is the page incorrect or am I doing something basic incorrect??

1 Answer 1

1

You are not doing anything wrong, you are signing different data thus getting a different signature.

In the Google example, if you copy and paste you'll notice that the braces are omitted in the clipboard; so it's signing the following URL:

http://maps.googleapis.com/maps/api/geocode/json?address=New+York&sensor=false&client=clientID

But when you tried it, you copied it verbatim, including the curly braces:

http://maps.googleapis.com/maps/api/geocode/json?address=New+York&sensor=false&client={clientID}

So rejoice yourself, your code is right, the only problem is in the sample data!

Sign up to request clarification or add additional context in comments.

1 Comment

I have this great eureka/argh mix at the moment haha, thank you so much! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.