"Python接收3个参数的参数?在哪里?"

2024-10-01 02:38:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用google safebrowsing api,以及以下代码:

def getlist(self, type):
    dlurl = "safebrowsing.clients.google.com/safebrowsing/downloads?client=api&apikey=" + api_key + "&appver=1.0&pver=2.2"
    phish = "googpub-phish-shavar"
    mal = "goog-malware-shavar"
    self.type = type
    if self.type == "phish":
        req = urllib.urlopen(dlurl, phish )
        data = req.read()
        print(data)

生成以下回溯:

^{pr2}$

我做错什么了?我看不出三个论点在哪里被通过。 顺便说一句,我打电话给

x = class()
x.getlist("phish")

Tags: 代码selfcomapidatadeftypegoogle
2条回答

功能urllib.urlopen打开由URL表示的网络对象以进行读取。如果URL没有方案标识符,它将打开一个文件。在

在第88行调用适当的开启器,这将导致209处的opener open_文件。在

如果你看一下函数:

  def open_file(self, url):
        """Use local file or FTP depending on form of URL."""

回答:你应该提供一个类似http://。。。在

基本上,您没有在url中提供方法,因此Python假设它是一个文件url,并试图将其作为一个不起作用的文件打开(并在失败的过程中抛出一个令人困惑的错误消息)。在

尝试:

dlurl = "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=api&apikey=" + api_key + "&appver=1.0&pver=2.2"

相关问题 更多 >