简体   繁体   English

如何修复 AttributeError:模块“requests.sessions”没有属性“post”

[英]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.

相关问题 AttributeError: 模块 'requests' 没有属性 'post' - AttributeError: module 'requests' has no attribute 'post' How to use requests.Sessions() to deliver a package to a URL with no 'action' attribute in the HTML in Python - How to use requests.Sessions() to deliver a package to a URL with no 'action' attribute in the HTML in Python 如何修复 AttributeError: &#39;module&#39; 对象没有属性 &#39;function&#39;? - How to fix AttributeError: 'module' object has no attribute 'function'? 如何修复“AttributeError:‘module’对象没有属性‘x’”? - how to fix "AttributeError: 'module' object has no attribute 'x' "? 如何修复AttributeError:模块&#39;testing2&#39;没有属性&#39;printPackage&#39;? - How to fix AttributeError: module 'testing2' has no attribute 'printPackage'? 如何在wfastcgi中修复“ AttributeError:模块没有属性&#39;wsgi&#39;” - How to fix “AttributeError: module has no attribute 'wsgi' ” in wfastcgi 如何修复:AttributeError:模块“整洁”没有属性“配置” - How to fix: AttributeError: module 'neat' has no attribute 'config' 如何修复 AttributeError:模块“tensorflow”没有属性“ConfigProto” - How can I fix AttributeError: module 'tensorflow' has no attribute 'ConfigProto' 如何修复 AttributeError:模块“magpylib”没有属性“源” - How to Fix AttributeError: module 'magpylib" has no attribute 'source' 如何修复“AttributeError:模块&#39;keras.backend&#39;没有属性..” - How to fix "AttributeError: module 'keras.backend' has no attribute.."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM