2013-05-07 74 views
0

部分:如何在python代碼中解決這個錯誤....'module'對象沒有屬性'Request'?含有錯誤代碼的

select_link = db.GqlQuery("select * from PhishTank where url= :1",str(updated_url)) 
    in_database_phishtank = False 
    for link in select_link: 
     if str(updated_url) == str(link.url): 
      in_database_phishtank = True 
      # chk for 7 days period , update the link 
      if (datetime.now()-link.timestamp) > timedelta(days = TIME_UPDATE): 
       # query to the site and update the datastore 
       url = "http://checkurl.phishtank.com/checkurl/" 
       parameters = {"url": "%s" % updated_url, 
           "app_key": "74283d86612c6b89de0b186882446e069dd071f65e9711aa374e9cdbd2ba7ffe", 
           "format":"json"} 
       data = urllib.urlencode(parameters) 
       req = urllib.Request(url, data) 
       try: 
        response = urllib2.urlopen(req) 
       except urllib.error.URLError as e: 
        self.redirect('/error') 
       json_post = response.read() 
       data = json.loads(json_post) 

回答

0

試試這個:

urllib.request.Request(url, data) 

要知道,在Python 3.X urllib在幾個模塊被分裂:urllib.requesturllib.parseurllib.error。您可能錯誤地導入了它。

相關問題