如何在python代码中解决此错误....'module'对象没有属性'Request'?

时间:2013-05-07 16:17:51

标签: python

包含错误的部分代码:

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)

1 个答案:

答案 0 :(得分:0)

试试这个:

urllib.request.Request(url, data)

请注意,在Python 3.x中,urllib分为几个模块:urllib.requesturllib.parseurllib.error。您可能导入错误。