如何在 Python 代码中解决此错误.... 'module'对象没有属性"请求"?



包含错误的代码部分:

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)

试试这个:

urllib.request.Request(url, data)

请注意,在Python 3中。x urllib分为几个模块:urllib.request, urllib.parseurllib.error

最新更新