TypeError: Object of type set is not JSON serializable while using requests
TypeError: Object of type set is not JSON serializable while using requests
所以,我正在编写一个使用请求库的程序。在尝试做某事时出现此错误:
Traceback (most recent call last):
File "C:\Users\myste\Desktop\Bang.com keker\e.py", line 10, in <module>
print(requests.get('https://www.bang.com/login_check',headers=headd,json=content).text)
File "C:\Python39\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Python39\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python39\lib\site-packages\requests\sessions.py", line 528, in request
prep = self.prepare_request(req)
File "C:\Python39\lib\site-packages\requests\sessions.py", line 456, in prepare_request
p.prepare(
File "C:\Python39\lib\site-packages\requests\models.py", line 319, in prepare
self.prepare_body(data, files, json)
File "C:\Python39\lib\site-packages\requests\models.py", line 469, in prepare_body
body = complexjson.dumps(json)
File "C:\Python39\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type set is not JSON serializable
这是我的代码:
import requests
headd = {
"User-Agent":"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
"Pragma":"no-cache" ,
"Accept":"*/*"
}
content = {
f"\"_username\":\"MY_EMAIL\",\"_password\":\"MY_PASSWORD\",\"_remember_me\":true"
}
print(requests.get('https://www.bang.com/login_check',headers=headd,json=content).text)
这个程序基本上做的是,它会获取您的电子邮件和密码的列表,然后检查它们是否有效。它的柜面你忘记了你的帐户密码。不要问我这个程序有什么意义因为我自己,我收到了制作这个的请求所以我正在制作 moyai
将 content
传递给 json
参数时,您传递的是 set
,但是,json
参数需要 dict
。
content = {
f"\"_username\":\"MY_EMAIL\",\"_password\":\"MY_PASSWORD\",\"_remember_me\":true"
}
>>> print(type(content))
<class 'set'>
相反,它应该是:
content = {"_username": "MY_EMAIL", "_password": "MY_PASSWORD", "_remember_me": "true"}
>>> print(type(content))
<class 'dict'>
您的内容实际上是 set
而不是 dict
。将其替换为:
content = {"_username": "my_email", "_password": "my-password"} # etc...
所以,我正在编写一个使用请求库的程序。在尝试做某事时出现此错误:
Traceback (most recent call last):
File "C:\Users\myste\Desktop\Bang.com keker\e.py", line 10, in <module>
print(requests.get('https://www.bang.com/login_check',headers=headd,json=content).text)
File "C:\Python39\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Python39\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python39\lib\site-packages\requests\sessions.py", line 528, in request
prep = self.prepare_request(req)
File "C:\Python39\lib\site-packages\requests\sessions.py", line 456, in prepare_request
p.prepare(
File "C:\Python39\lib\site-packages\requests\models.py", line 319, in prepare
self.prepare_body(data, files, json)
File "C:\Python39\lib\site-packages\requests\models.py", line 469, in prepare_body
body = complexjson.dumps(json)
File "C:\Python39\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type set is not JSON serializable
这是我的代码:
import requests
headd = {
"User-Agent":"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
"Pragma":"no-cache" ,
"Accept":"*/*"
}
content = {
f"\"_username\":\"MY_EMAIL\",\"_password\":\"MY_PASSWORD\",\"_remember_me\":true"
}
print(requests.get('https://www.bang.com/login_check',headers=headd,json=content).text)
这个程序基本上做的是,它会获取您的电子邮件和密码的列表,然后检查它们是否有效。它的柜面你忘记了你的帐户密码。不要问我这个程序有什么意义因为我自己,我收到了制作这个的请求所以我正在制作 moyai
将 content
传递给 json
参数时,您传递的是 set
,但是,json
参数需要 dict
。
content = {
f"\"_username\":\"MY_EMAIL\",\"_password\":\"MY_PASSWORD\",\"_remember_me\":true"
}
>>> print(type(content))
<class 'set'>
相反,它应该是:
content = {"_username": "MY_EMAIL", "_password": "MY_PASSWORD", "_remember_me": "true"}
>>> print(type(content))
<class 'dict'>
您的内容实际上是 set
而不是 dict
。将其替换为:
content = {"_username": "my_email", "_password": "my-password"} # etc...