Search code examples
pythonflaskamazon-product-api

Flask session dictionary get reset


The same method works; if I get rid of a specific value of a key.

I have a field called 'Feature' which helps me get items descriptions from amazon; I've made sure it works correctly by printing. It's a plain string; I've made sure and double checked it. Using type()

This is how I'm setting flask session dictionary:

app = Flask(__name__)
app.config['SECRET_KEY'] = 'yo'
@app.route('/', methods=['GET','POST'])
def index():
   authenticated_url = authenticate(Availability='Available',Operation='ItemSearch',Keywords=str(query),SearchIndex='Electronics', ResponseGroup='ItemAttributes')
   product = authenticated_url['ItemSearchResponse']['Items']['Item']
   arr = []
   for items in product:
       main_dictionary = {}
       sub_dictionary = {}
       sub_dictionary['price'] =  items['ItemAttributes']['FormattedPrice']
       featureLists = items['ItemAttributes']['Feature']
       emptyFeatureStr = ' '
       for items in featureLists:
           emptyFeatureStr += items
       sub_dictionary['Feature']=emptyFeatureStr
       main_dictionary[items['ASIN']]=sub_dictionary # I construct a dictionary whose key is ASIN number and values
       arr.append(main_dictionary) #I append my new dictionary into an array. 

   session['searchResults']=arr
   print session['searchResults']
   #Here I try to set the flask session dictionary key to searchResults
   # Verfied/made sure that this is set correct; up until here everything works; my dictionary is set as expected.

ISSUE:

@app.route('/profile/<asin>', methods=['GET','POST'])
def profilePage(asin):

    return str(session.get('searchResults')

When I do that it gives me null. The moment I get rid of feature it seems to be working as expected... like the price is displayed and amazon calls; and flask session is set properly. I have no idea the momment I set feature key/value it stops working.

This is an example of what is being passed into feature

TRUVIEW 0.45x WIDE ANGLE LENS - CAPTURE 45% MORE PICTURE WITH EVERY SNAP: Shoot stunning photos of people, pets, travel scenery, landscapes, architecture, selfies and more. NO DARK CORNERS (vignetting) like cheaper lenses. Crafted from aircraft-grade aluminum and premium optical glass for durability and clarity. Multi-element, coated glass lenses minimize ghosting, reflections, lens flare, and other artifacts. Mirrorless camera lenses ideal for hobbyists and photography pros alike.CLARUS 15x MACRO LENS + TRUGRIP LENS CLIP - MARVEL YOUR SENSES. MAGNIFY NEARBY SUBJECTS FOR BREATHTAKING, SUPER CLOSE-UP PHOTOS: Capture all the intricacies and details with precision-focus for razor crisp macro photos every time. THE TRUGRIP LENS CLIP offers SUPERIOR GRIPPING POWER to fasten your lenses to your cellphone when you're in action mode, framing your next perfect shot. The lens clip has soft rubber pads and won't leave scratches or marks on your phone.RECHARGEABLE LED FILL LIGHT - The GlowClip LED light clips ANYWHERE on your phone and includes 3 settings: Low, Medium, and High. Instantly illuminate your subject and surroundings with warm continuous light. The warm and natural LED light is superior to your smartphone's built in flash - which often blinds people and yields unnatural color in your photos - especially in darker settings and venues. Say goodbye to frustrating photo "retakes" and hello to brilliant photos the first time.DURACASE AND QUICK-RELEASE LANYARD - TRANSPORT AND PROTECT YOUR LENS KIT: Perfect for taking your lens kit and LED light with you on the fly. The DuraCase stores and protects all lens kit components snugly and safely while the quick-release lanyard is the perfect way to carry your lenses on your next outing. Just drape the lanyard and lens around your neck. The quick-release head makes it a cinch to detach your lens and clip it to your phone in a flash so you never miss another photo moment.PROFESSIONAL HD PHOTOS & VIDEOS - A huge hit at social and family gatherings. Designed for hobbyists as well as today's most demanding professionals; content creators, bloggers, and social media marketers who count on their smartphone camera to grow their business and brand. Package Contents: TruView 0.45x Wide Angle Lens, Clarus 15x Macro Lens, Lens Clip, GlowClip Mini Rechargeable LED Light + Charging Cable, DuraCase, Cleaning Cloth, Money Back Guarantee AND Lifetime Warranty.

Solution

  • You seem to be storing too much data when using the client-side Session:

    A note on cookie-based sessions: Flask will take the values you put into the session object and serialize them into a cookie. If you are finding some values do not persist across requests, cookies are indeed enabled, and you are not getting a clear error message, check the size of the cookie in your page responses compared to the size supported by web browsers.