Flask 会话字典重置

Flask session dictionary get reset

同样的方法有效;如果我去掉某个键的特定值。

我有一个名为 'Feature' 的字段,它可以帮助我从亚马逊获取商品描述;我已经通过打印确保它正常工作。这是一个普通的字符串;我已经确定并仔细检查了它。使用类型()

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

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。在我摆脱功能的那一刻,它似乎按预期工作……就像显示价格和亚马逊电话一样;烧瓶会话设置正确。我不知道我设置功能的那一刻 key/value 它停止工作了。

这是传递给 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.

您似乎在使用客户端时存储了太多数据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.