python 参数有 3 个参数?在哪里?

发布于 2024-09-28 20:49:04 字数 901 浏览 0 评论 0原文

我正在使用 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")

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把梦留给海 2024-10-05 20:49:04

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

尝试:

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

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"
各自安好 2024-10-05 20:49:04

函数 urllib.urlopen 打开一个由 URL 表示的网络对象以供读取。如果 URL 没有方案标识符,则会打开一个文件。

适当的开启器在第 88 行被调用,导致开启器 open_file 在 209 处。

如果你看一下这个函数:

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

答案:你应该提供一个类似 http://... 的方案。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文