views:

49

answers:

2

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:

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")
+2  A: 

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"
Chris B.
thanks you guys. I had originally been using httplib and ended up deciding on urllib, forgot to change it. Much appreciated.
Stev0
A: 

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://...

pyfunc