Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:03:53+00:00 2026-06-18T14:03:53+00:00

On GAE I’m using hmac to produce a signature for an AWS API request.

  • 0

On GAE I’m using hmac to produce a signature for an AWS API request. My code was originally this:

import urllib
import urllib2
import time
import hmac
import base64
from hashlib import sha256 as sha256

class AmazonProductAdvertisingAPI:

    secret_access_key = '...'
    my_hmac = hmac.new(secret_access_key, digestmod=sha256)

    def get_signed_url(self, params):

        ....

        # Sign it
        self.my_hmac.update('GET' + "\n" + server + "\n" + path + "\n" + paramstring)
        urlstring = urlstring + "&Signature=" + \
            urllib.quote(base64.encodestring(self.my_hmac.digest()).strip())

        return urlstring

With this, I found that the API request (using the URL given by get_signed_url) if and only if the request was a “cold start” for the instance, e.g. after I’d deployed the code and was running it for the first time.

However, subsequent requests failed, with AWS claiming that the signature was invalid. This was resolved by moving my_hmac to within the method, so that it was a variable within the method rather than an instance variable within the class.

...
def get_signed_url(self, params):
    my_hmac = hmac.new(self.secret_access_key, digestmod=sha256)
    ...

I have one question: why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:03:54+00:00Added an answer on June 18, 2026 at 2:03 pm

    Your my_hmac variable was a class variable; one shared by all instances of the class.

    This means that for every call to .get_signed_url() the self.my_hmac.update() call would add data to the digest, across instances, globally to the application.

    Since you only want to calculate the digest for one string only, (the "GET ..." string) and not for all strings cumulatively, you must create a new hmac object for each new digest you want to calculate.

    Note the documentation for the .update()` method:

    Update the hash object with the string arg. Repeated calls are equivalent to a single call with the concatenation of all the arguments: m.update(a); m.update(b) is equivalent to m.update(a+b).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using GAE with python and I came across this problem, I'm trying to
In my GAE project I started with JPA 1.0 and this code worked great:
I've got a GAE in Python and I am using the Channel API: https://developers.google.com/appengine/docs/python/channel/functions
GAE not works with: import com.google.appengine.repackaged.com.google.common.base.Hash; import com.google.appengine.repackaged.com.google.common.io.ByteStreams; and my code: byte[] inputBytes; try
On GAE this line of code: file_name = files.blobstore.create(mime_type='image/png') drops google.appengine.runtime.DeadlineExceededError Here is the
I am using GAE plugin for eclipse and wanted to know if the plugin
I am using GAE's high replication datastore. I previously downloaded a table in csv
I am using GAE with python and I can ask users to sign in
I'm using GAE[JAVA] to do some image processing. GAE will not allow write file
GAE remote API for java :Configuring Remote API on an App Engine Client RemoteApiInsideAppEngineExample(String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.