2017-10-17 16 views
-1

私はgoogleで検索しようとしましたが、いくつかのドキュメントとサンプルコードを調べましたが、if文でテストするCookieの値を読み取る方法がわかりませんでした。クッキーの値を取得する#Python

私は 'sessionid'という名前のクッキーを作成しており、その値はユーザーの電子メールのハッシュです。

私は私ができるならば、私は

3Xのpythonを使用しています

for name in request.cookies: 

    #I am trying to get the value of a sessionid cookie to compare if that 
    #hash matches with the hash value of the email sent 

     value = request.cookies.get('sessionid') 
     # value = request.cookies I also tried this 
     items = value.items 

     for a, b in items: 

     if b == hashlib.md5(_email.encode('utf')).hexdigest(): 

      response = make_response() 
      response.headers['NewSession'] = 'new' 
      return LoginPassed(name) 
     return LoginError() 

...私は特定の電子メールがサイトを訪問したことを言うことができるかどうCookieが存在しているかどうかをチェックしたい

sessionid = hashlib.md5(user.encode('utf')).hexdigest() 
#generates the session id for the cookie 

response = make_response(open('LoginPassed.xml').read()) 
response.set_cookie('sessionid', sessionid) 

クッキーの名前を見つけ、if文の何かと比較するためにその値をどのように読み取るのですか?

答えて

0
value = request.cookies.get('sessionid') 
# The request.cookies.get(nome_do_cookie) returns the value of the cookie 

    if value == hashlib.md5(_email.encode('utf')).hexdigest(): 
     print(value) 
     print(hashlib.md5(_email.encode('utf')).hexdigest()) 

     response = make_response() 
     response.headers['NewSession'] = 'new' 
     return LoginPassed(name) 
    return LoginError() 

問題は、間違った検査をしていることに気付かなかったことでした。

関連する問題