GVKun编程网logo

Function()恰好接受2个参数(给定3个)(接收两个参数的构造方法)

21

在这里,我们将给大家分享关于Function的知识,让您更了解恰好接受2个参数的本质,同时也会涉及到如何更有效地$(document).ready(function()VS$(function(){、

在这里,我们将给大家分享关于Function的知识,让您更了解恰好接受2个参数的本质,同时也会涉及到如何更有效地$(document).ready(function()VS $(function(){、dbus_to_python()正好接受1个参数?、extIOWrapper.write() 只需要一个参数(给出 2 个)、Flask App无法启动(TypeError:code()至少接受14个参数(给定13个参数))的内容。

本文目录一览:

Function()恰好接受2个参数(给定3个)(接收两个参数的构造方法)

Function()恰好接受2个参数(给定3个)(接收两个参数的构造方法)

我正在使用python从另一个文件的另一类的方法中调用一个文件中的一个类中的方法

假设我的文件abc.py包含

class data :         def values_to_insert(a,b):               ......                ......

另一个文件是 def.py

import abcclass values:      data=abc.data()      def sendvalues():          a=2          b=3          data.values(a,b)

当我运行此文件时,出现错误: values() takes exactly 2 arguments (3 given)

答案1

小编典典

如果在类中,则您的方法应为:

def values_to_insert(self, a, b):

您可以在此处阅读有关其原因的信息。

$(document).ready(function()VS $(function(){

$(document).ready(function()VS $(function(){

$(document).ready(function(){})vs $(function(){})
和我应该以$表格或新jQuery(document).ready(function(){ })方式书写的区别是什么?

如果我加载google.setOnLoadCallback(function() {了Google api是更好的方法?还是同一件事?

我也看到人们使用 $(function($){})

有人可以帮我,我迷路了。当我不知道所写的代码时,我会烦扰我。我想我应该阅读一下图书馆。全部都定义为同一件事吗?

dbus_to_python()正好接受1个参数?

dbus_to_python()正好接受1个参数?

我试图firewalld通过Pythondbus模块进行控制。

我想为当前的运行时以及永久配置添加一个IP地址到受信任的区域。

以下firewalld是dbus界面的文档:http
:
//manpages.ubuntu.com/manpages/wily/man5/firewalld.dbus.5.html

什么有效:运行时配置

我可以将其添加到运行时配置中:

def trustIP(ip):    '''''' firewalld must already be running ''''''    from dbus import SystemBus    bus = SystemBus()    runtimeProxy = bus.get_object(''org.fedoraproject.FirewallD1'',                                 ''/org/fedoraproject/FirewallD1'')    runtimeProxy.addSource(''trusted'', ip)

很简单

什么不起作用:永久配置

事实证明,将其添加到永久配置中比较困难。到目前为止,我已经尝试过以下方式:

>>> from dbus import SystemBus>>> bus = SystemBus()# First I need to find out which object is for the trusted zone...>>> config = bus.get_object(''org.fedoraproject.FirewallD1'',                           ''/org/fedoraproject/FirewallD1/config'')>>> config.getZoneByName(''trusted'')dbus.ObjectPath(''/org/fedoraproject/FirewallD1/config/zone/7'')>>> permanentProxy = bus.get_object(''org.fedoraproject.FirewallD1'',                                    ''/org/fedoraproject/FirewallD1/config/zone/7'')# A quick check to make sure I have the right object:>>> permanentProxy.getShort()dbus.String(u''Trusted'')# Exactly what I expected, so move on and...>>> permanentProxy.addSource(''aaa.xxx.yyy.zzz'')  # Actual ip removed...Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in __call__    **keywords)  File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking    message, timeout)dbus.exceptions.DBusException:    org.freedesktop.DBus.Python.dbus.exceptions.DBusException:        dbus_to_python() takes exactly 1 argument (2 given)

我还尝试了检查permanentProxy.getDescription(),该检查返回了应有的描述,并且尝试permanentProxy.setDescription(''test'')了失败,并且堆栈跟踪与完全相同permanentProxy.addSource(''aaa.xxx.yyy.zzz'')

我会得出一个结论,即该错误位于pythondbus模块中,并假定它以某种方式无法正确处理参数,除了runtimeProxy.addSource(''trusted'',ip)涉及两个参数且可以正常工作的事实。config.getZoneByName(''trusted'')甚至具有与永久代理.addSource(’aaa.xxx.yyy.zzz’)`相同的签名,并且只有一个字符串,并且可以完美地工作。

所以也许我缺少某种奇怪的东西?但是我不知道那会是什么…

我尝试过的更多东西没有成功

我考虑了可能完全addSource不使用字符串参数调用并且可能以某种方式咖喱的可能性,因此我尝试了以下方法:

>>> permanentProxy.addSource()Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in __call__    **keywords)  File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking    message, timeout)dbus.exceptions.DBusException: org.freedesktop.DBus.Python.TypeError: Traceback (most recent call last):  File "/usr/lib/python2.7/site-packages/slip/dbus/service.py", line 123, in reply_handler    result = method(self, *p, **k)TypeError: addSource() takes at least 2 arguments (2 given)

现在这甚至更奇怪了。我在另一个回溯中有一个回溯,坚持我需要传递至少两个参数,还说我给了它两个参数(实际上我只给了一个,所以怎么样想出两个吗?)

我尝试过的一些尝试均未成功:

>>> permanentProxy.addSource(dbus_interface=''org.fedoraproject.FirewallD1.config.zone'')ERROR:dbus.connection:Unable to set arguments () according to signature u''s'': <type ''exceptions.TypeError''>: More items found in D-Bus signature than in Python argumentsTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in __call__    **keywords)  File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 641, in call_blocking    message.append(signature=signature, *args)TypeError: More items found in D-Bus signature than in Python arguments>>> permanentProxy.addSource(''aaa.xxx.yyy.zzz'', dbus_interface=''org.fedoraproject.FirewallD1.config.zone'')Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in __call__    **keywords)  File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking    message, timeout)dbus.exceptions.DBusException:    org.freedesktop.DBus.Python.dbus.exceptions.DBusException:        dbus_to_python() takes exactly 1 argument (2 given)>>> from dbus import Interface>>> Interface(permanentProxy, ''org.fedoraproject.FirewallD1.config.zone'').addSource(''aaa.xxx.yyy.zzz'')Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in __call__    **keywords)  File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking    message, timeout)dbus.exceptions.DBusException:    org.freedesktop.DBus.Python.dbus.exceptions.DBusException:        dbus_to_python() takes exactly 1 argument (2 given)

加!

这确实看起来像是一个错误dbus……某种程度上,它最初是错误地解决了,addSource并认为它需要更少的参数,但是如果给它更少的参数,它将通过错误的检查,然后正确地解决并失败,因为您的参数不匹配。

无论如何,这是我的理论。有人看到我没有的东西吗?如果确实存在此错误,有什么办法可以解决此错误?IE
…我可以在dbus上使用某种内部方法来强制它调用正确的方法吗?

答案1

小编典典

以下对我有用:

>>> import dbus>>> bus = dbus.SystemBus()>>> config = bus.get_object(''org.fedoraproject.FirewallD1'',...                            ''/org/fedoraproject/FirewallD1/config'')>>> path = config.getZoneByName(''trusted'')>>> zone = bus.get_object(''org.fedoraproject.FirewallD1'', path)>>> zone.addSource(''192.168.1.0/24'')

此时,如果查看/etc/firewalld/zones/trusted.xml,可以看到已按预期添加了源地址:

<?xml version="1.0" encoding="utf-8"?><zone target="ACCEPT">  <short>Trusted</short>  <description>All network connections are accepted.</description>  <interface name="docker0"/>  <interface name="virbr0"/>  <source address="192.168.1.0/24"/></zone>

…表明我已经成功更改了持久配置。

如果我在第二个get_object调用中使用文字路径,而不是中的返回值,则以上内容也适用config.getZoneByName

为了它的价值,我正在跑步:

  • 浅顶软呢帽23
  • Firewalld-0.3.14.2-4.fc23.noarch
  • dbus-1.10.6-1.fc23.x86_64
  • dbus-python-1.2.0-12.fc23.x86_64

更新

您没有看到任何新内容,因为您使用的是CentOS,而不是Fedora。解决此特定任务的最简单方法似乎是使用firewallFirewallD随附的python模块。以下内容适用于CentOS
7:

>>> from firewall.client import *>>> client = FirewallClient()>>> zone = client.config().getZoneByName(''public'')>>> settings = zone.getSettings()>>> settings.addSource(''192.168.1.0/24'')>>> zone.update(settings)

另一个更新

浏览源代码到firewall.client模块,您可以通过如下所示的直接dbus进行此操作:

>>> zone = bus.get_object(''org.fedoraproject.FirewallD1'', path)>>> settings = zone.getSettings()>>> settings[11].append(''192.168.20.0/24'')>>> zone.update(settings)

能正常工作下的CentOS ......但你的时候使用更好的firewall模块。

extIOWrapper.write() 只需要一个参数(给出 2 个)

extIOWrapper.write() 只需要一个参数(给出 2 个)

如何解决extIOWrapper.write() 只需要一个参数(给出 2 个)?

我正在尝试制作一个程序来使用文件创建一个 id pw。

这是我的代码:

n = input("enter your name")
print("Enter Your Password:-")

f = open("user_ids.txt","a")
f.write(n,"\n")
f.write(p1)
f.close()

运行此代码显示以下错误:

extIOWrapper.write() takes exactly one argument (2 given)

解决方法

您正在尝试将多个参数传递给 write 函数。

正如 Andy Knight 所说,您可能指的是 f.write(n+"\n"),因为这将写入 n 的值,然后换行。

在 python 中,print 语句允许您将字符串作为多个参数传递(print("ABC","DEF") prints ABC DEF),但是您不能用许多其他函数来做到这一点,所以要小心。

Flask App无法启动(TypeError:code()至少接受14个参数(给定13个参数))

Flask App无法启动(TypeError:code()至少接受14个参数(给定13个参数))

我在使用im Flask 1.0.2,Werkzeug 0.15.2和他还使用Python 3.7.3的课程中遇到了同样的问题。

大多数答案都倾向于在werkzeug版本中出现一些错误,因此我决定卸载所有内容并使用最新的东西……然后解决了。 现在我使用烧瓶1.1.2和Werkzeug 1.0.1。

希望,如果您仍然需要它,可能会对您有所帮助。

,

如果您不依赖于特定版本的 Flask 或 Werkzeug,根据您的 requirements.txt 并且乐于运行最新版本,那么您可以运行使用以下命令升级两个库。

pip install --upgrade werkzeug
pip install --upgrade flask

如果您必须坚持使用特定版本的 Flask(或 Werkzeug),您可以使用以下命令安装该版本

e.g. pip install --no-cache-dir -I flask==1.0.2

如果出于某种原因,上面的代码也没有安装可以正常工作的 Werkzeug,那么您可以在下面运行此命令/hack 以查看哪些版本可用于 Werkzeug,并尝试使用上述命令手动安装特定版本>

pip install --use-deprecated=legacy-resolver werkzeug==

它会返回一个错误输出,列出它可以找到的所有版本

错误:找不到满足要求的版本 werkzeug==(来自版本:0.1、0.2、0.3、0.3.1、0.4、0.4.1、0.5、 0.5.1,0.6,0.6.1,0.6.2,0.7,0.7.1,0.7.2,0.8,0.8.1,0.8.2,0.8.3,0.9,0.9.1,0.9.2,0.9. 3,0.9.4,0.9.5,0.9.6,0.10,0.10.1,0.10.2,0.10.4,0.11,0.11.1,0.11.2,0.11.3,0.11.4,0.111.5 0.11.6,0.11.7,0.11.8,0.11.9,0.11.10,0.11.11,0.11.12,0.11.13,0.11.14,0.11.15,0.12,0.1.12,0.12. 0.13,0.14,0.14.1,0.15.0,0.15.1,0.15.2,0.15.3,0.15.4,0.15.5,0.15.6,0.16.0,0.16.1,1.10.0.rc 0,1.0.1,2.0.0rc1,2.0.0rc2,2.0.0rc3,2.0.0rc4) 错误:没有找到与 werkzeug 匹配的分布==

我们今天的关于Function恰好接受2个参数的分享就到这里,谢谢您的阅读,如果想了解更多关于$(document).ready(function()VS $(function(){、dbus_to_python()正好接受1个参数?、extIOWrapper.write() 只需要一个参数(给出 2 个)、Flask App无法启动(TypeError:code()至少接受14个参数(给定13个参数))的相关信息,可以在本站进行搜索。

本文标签: