如何解决TypeError get()在使用get方法的Python请求中恰好接受2个参数(给定3个)
作者:互联网
在Python中使用Request对象时出现错误.
下面是我的代码.
class APIDOC(Document):
def request_api(self):
method_type = self.method_type
api = self.api
parameters = self.parameters
session_object = requests.session()
self.get_login(session_object)
if method_type == "POST":
data = {}
for param in parameters:
data[param.key] = param.value
response = session_object.post(api,data)
if response.status_code == 200:
return response.text
else:
return "Error while getting response error code:{0}".format(response.status_code)
elif method_type == "GET":
data = {}
for param in parameters:
data[param.key] = param.value
print("____________________________",data)
response = session_object.get(api,data)
if response.status_code == 200:
return response.text
else:
return "Error while getting response error code:{0}".format(response.status_code)
在python中根据请求转发一个文档后,我发现以下“ GET”方法的问题
r = requests.get('http://httpbin.org/get', params=payload)
但是在执行相同的操作时出现错误
response = session_object.get(api,data)
TypeError: get() takes exactly 2 arguments (3 given)
解决方法:
要使用GET发送参数,您需要通过关键字指定它们:
session_object.get(api, params=data)
标签:python-requests,python 来源: https://codeday.me/bug/20191109/2012570.html