我正在使用 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)
产生以下回溯:
File "./test.py", line 39, in getlist
req = urllib.urlopen(dlurl, phish )
File "/usr/lib/python2.6/urllib.py", line 88, in urlopen
return opener.open(url, data)
File "/usr/lib/python2.6/urllib.py", line 209, in open
return getattr(self, name)(url, data)
TypeError: open_file() takes exactly 2 arguments (3 given)
我在这里做错了什么?我看不出 3 个参数被传递到哪里。 顺便说一句,我用这个来称呼
x = class()
x.getlist("phish")
最佳答案
基本上,您没有在 url 中提供方法,因此 Python 假定它是一个文件 URL,并尝试将其作为文件打开 - 这不起作用(并在该过程中抛出令人困惑的错误消息失败)。
尝试:
dlurl = "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=api&apikey=" + api_key + "&appver=1.0&pver=2.2"
关于python 参数有 3 个参数?在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4029747/