2013-08-30 3 views
0

받는 사람의 전자 메일 주소로 링크 (아래)가 전송되는 전자 메일 확인을 설정하려고합니다. 링크를 클릭하면 'post_id'를 취할 프로세스로 이동하여 매개 변수 'i'와 연관된 사용자 레코드의 키와 비교합니다.URL 매개 변수에 대한 db 키 테스트가 실패 함 (Python)

연결 URL이 동일한 경우 연결 URL이 유효합니다. 나는 단지 시험을받을 수 없다.

링크 = http://letshudder.appspot.com/email/confirmation/5662278724616192?i=MichaelClay

코드

def get(self, post_id): 
     logging.debug("In email confirmation for userid %s" % post_id) 

     linkid = self.request.GET.get("i") 
     uid = User.by_id_name(linkid) 
     logging.debug("The uid of the inviter is %s" % uid) 
     logging.debug("with a length of %s" % len(str(uid))) 
     logging.debug("This should match the id value from the link: %s" % post_id) 
     logging.debug("with a length of %s" % len(str(post_id))) 

     if uid >= post_id: 
      logging.debug("UID wins") 

     if post_id >= uid: 
      logging.debug("post_id wins") 

     if uid != post_id: 
      logging.debug("UID and LINKID did not match") 
      self.redirect('/invalid_url') 
      return 

. . .

디버그 출력 :

D 2013-08-29 19:18:28.871 In email confirmation for userid 5662278724616192 

I 2013-08-29 19:18:28.887 the userid is: MichaelClay 

D 2013-08-29 19:18:28.887 The uid of the inviter is 5662278724616192 

D 2013-08-29 19:18:28.887 with a length of 16 

D 2013-08-29 19:18:28.887 This should match the id value from the link: 5662278724616192 

D 2013-08-29 19:18:28.887 with a length of 16 

D 2013-08-29 19:18:28.887 post_id wins 

내가 Google 애플리케이션 엔진에 파이썬 2.7을 실행하고 있습니다. 어떤 아이디어?

답변

0

uid = User.by_id_name(linkid)의 결과는 사용자 ID가 아니라 사용자 개체가됩니다. 그것의 str 방법은 물건을 로깅 할 때 uid처럼 보이지만 그렇지 않다는 것을 의미합니다. 이는 비교가 실패 함을 의미합니다.

코드가 작동하려면 str(uid) == linkid을 사용해야합니다.

이것을 증명하려면 tryr (uid) 대신 repr (uid) 로깅을 시도하십시오.

관련 문제