Flask会话字典被重置

问题描述 投票:0回答:1

同样的方法有效;如果我摆脱了一个密钥的特定值。

我有一个名为'功能'的字段,可以帮助我从亚马逊获得物品描述;我确保它通过打印正常工作。这是一个简单的字符串;我已经确定并仔细检查过它。使用type()

这就是我设置瓶子会话字典的方式:

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.

问题:

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

    return str(session.get('searchResults')

当我这样做它给我null。我摆脱功能的那一刻似乎按预期工作......就像价格显示和亚马逊电话;和烧瓶会话设置正确。我不知道我设置功能键/值的功能它停止工作。

这是传递给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.
python flask amazon-product-api
1个回答
2
投票

使用客户端Session时,您似乎存储了太多数据:

关于基于cookie的会话的注释:Flask将获取您放入会话对象的值并将它们序列化为cookie。如果您发现某些值不会在请求中保留,则确实启用了Cookie,并且您没有收到明确的错误消息,请检查页面响应中的Cookie大小与Web浏览器支持的大小相比较。

© www.soinside.com 2019 - 2024. All rights reserved.