2010-10-27 38 views
2

我与谷歌安全浏览API的使用,和下面的代码:python参数取3个参数?哪里?

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") 

回答

4

基本上,你没有在URL中提供的方法,所以Python假定它是一个文件的URL,并试图打开它作为一个文件 - 它没有按不起作用(并在失败过程中抛出一个令人困惑的错误消息)。

尝试:

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

谢谢你们。我原来一直在使用httplib,最后决定使用urllib,忘记改变它。非常感激。 – Stev0 2010-10-27 03:45:47

+0

thnaks它帮助我拯救我的屁股! – user993563 2012-04-06 11:13:23

0

功能了urllib.urlopen打开一个URL读取表示网络对象。如果该URL没有方案标识符,则会打开一个文件。

适当的揭幕战被称为在这导致在209

如果你看一下功能开罐器OPEN_FILE线88:

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

答:你应该提供类似计划http://...