项目快速概述:我正在尝试使用LoPy为我的Philips Hue灯制作一个控制器。要从Hue API获取信息,我需要进行连接(有效)并将信息发送到API,问题出在那部分。
由于LoPy无法使用我正在使用的“ urequests”库中的“ requests”库,因此用于发送请求的功能如下所示:
urequests.py
CREATE PROCEDURE [dbo].[SearchUserPermission]
@UserId bigint,
@ParentModuleId Bigint
AS
BEGIN
SET NOCOUNT ON
Declare @strSQLQuery AS VARCHAR(3000) =null;
Declare @strCriteria AS VARCHAR(1000)=null;
BEGIN
SET @strCriteria = ' WHERE 1=1'
IF(@UserId > 0)
BEGIN
SET @strCriteria=@strCriteria + ' AND UserId =' + CONVERT(VARCHAR,@UserId)
END
IF( @ParentModuleId > 0)
BEGIN
SET @strCriteria=@strCriteria + ' AND ParentModuleId=' + Convert(varchar,@ParentModuleId)
END
SET @strSQLQuery ='Select * From (
SELECT
*
FROM Module_Mst
LEFT outer join UserPermissions_Mst
on UserPermissions_Mst.ModuleId=Module_Mst.moduleId AND Module_Mst.IsVisible=1
' +@strCriteria + ' ) AS TempUserPermission'
if (LEN(@strCriteria) > 0 )
BEGIN
SET @strSQLQuery = @strSQLQuery + ' ORDER By OrderNo '
END
END
--Print(@strSQLQuery)
EXEC (@strSQLQuery)
END
使用该库,我正在使用“ qhue”库来获取有关我的灯光的信息,这可以通过以下功能来实现:
qhue.py
def head(url, **kwargs):
return request("HEAD", url, **kwargs)
def get(url, **kwargs):
return request("GET", url, **kwargs)
def post(url, **kwargs):
return request("POST", url, **kwargs)
def put(url, **kwargs):
return request("PUT", url, **kwargs)
def patch(url, **kwargs):
return request("PATCH", url, **kwargs)
def delete(url, **kwargs):
return request("DELETE", url, **kwargs)
因此,当我请求灯光信息时,在qhue.py中调用了“ else”,因此在urequests.py中调用了get()函数,但是由于某些原因,我一直遇到此错误:>
回溯(最近通话最近): 文件“ main.py”,行279 在致电中,文件“ qhue.py”,第39行 TypeError:函数不包含关键字参数
main.py代码获取所有指示灯(b = qhue.py中的函数)
def __call__(self, *args, **kwargs):
url = self.url
for a in args:
url += "/" + str(a)
http_method = kwargs.pop('http_method',
'get' if not kwargs else 'put').lower()
if http_method == 'put':
r = requests.put(url, data=json.dumps(kwargs, default=list), timeout=self.timeout)
elif http_method == 'post':
r = requests.post(url, data=json.dumps(kwargs, default=list), timeout=self.timeout)
elif http_method == 'delete':
r = requests.delete(url, timeout=self.timeout)
else:
r = requests.get(url, timeout=self.timeout)
if r.status_code != 200:
raise QhueException("Received response {c} from {u}".format(c=r.status_code, u=url))
resp = r.json()
if type(resp) == list:
errors = [m['error']['description'] for m in resp if 'error' in m]
if errors:
raise QhueException("\n".join(errors))
return resp
该错误如何发生?如何解决?在我看来,使用** kwargs可以使函数定义自己的参数(例如timeout =和data =)