I'm working with the google safebrowsing api, and the following code:
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)
Produces the following trace back:开发者_StackOverflow
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)
What am I doing wrong here? I cant spot where 3 arguments are being passed. BTW, I'm calling this with
x = class()
x.getlist("phish")
Basically, you didn't supply a method in the url, so Python assumed it was a file URL, and tried to open it as a file--which doesn't work (and throws a confusing error message in the process of failing).
Try:
dlurl = "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=api&apikey=" + api_key + "&appver=1.0&pver=2.2"
The function urllib.urlopen opens a network object denoted by a URL for reading. If the URL does not have a scheme identifier, it opens a file.
The appropriate opener is called at line 88 which leads to opener open_file at 209.
If you look at the function:
def open_file(self, url):
"""Use local file or FTP depending on form of URL."""
Answer: you should be providing a scheme like http://...
精彩评论