python 参数有 3 个参数?在哪里?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您没有在 url 中提供方法,因此 Python 假定它是一个文件 URL,并尝试将其作为文件打开——这不起作用(并在失败的过程中抛出令人困惑的错误消息) 。
尝试:
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:
函数 urllib.urlopen 打开一个由 URL 表示的网络对象以供读取。如果 URL 没有方案标识符,则会打开一个文件。
适当的开启器在第 88 行被调用,导致开启器 open_file 在 209 处。
如果你看一下这个函数:
答案:你应该提供一个类似 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:
Answer: you should be providing a scheme like http://...