我在给我1个参数但给出2个参数时出错,最终目标是打印json正文
url_get = 'http://ludwig.corp.podiumdata.com:/qdc/entity/v1/getEntities?type=EXTERNAL&count=2&sortAttr=name&sortDir=ASC'
session = requests.Session()
r = session.get(url_cookie, auth=(username,password), verify=False)
print('--------------------- 1. status_code ----------------------------------')
print(r.status_code)
print('--------------------- 1. headers ----------------------------------')
print(r.headers)
print('--------------------- 1. content ----------------------------------')
data = r.json(url_get)
print(data)
print('--------------------- 1. cookies ----------------------------------')
print(session.cookies, r.cookies)
print('--------------------- 1. cookies get_dict ----------------------------------')
print(session.cookies.get_dict())
print("7")
File "<ipython-input-36-b971c3b17ea5>", line 67, in <module>
data = r.json(url_get)
TypeError: json() takes 1 positional argument but 2 were given```
答案 0 :(得分:0)
这是因为您尝试在URL上调用tableView.reloadData
,该URL不适合python中的任何有效对象。
json.loads
我确定错误消息看起来很熟悉:)
接下来,当您在import json
x = json.loads('[1, 2, 3]')
x # This gets evaluated to a list
[1, 2, 3]
y = json.loads('hi i am a string')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mm92400/anaconda3/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/Users/mm92400/anaconda3/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/mm92400/anaconda3/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
对象上调用json
方法时,您无需传递任何内容,因为请求的主体将隐式传递给{{1} }解析器:
Request
json
的文档为here,r = requests.get(some_url)
r.json() # don't put anything in the parens here
的文档为here
答案 1 :(得分:0)
您的意思是说r.json()
。 r
是代表从服务器返回的数据的响应对象。对此调用json()
方法(尝试)将JSON中的数据解析为python数据结构。您不能将任何其他参数传递给该函数。