重新安装软件包后解决“ AttributeError:模块'requests'没有属性'方法'”错误吗?

时间:2019-07-08 00:08:43

标签: python flask request package

我正在尝试使用userName = requests.form.get ['username']来使变量userName等于表单输入,但是我在烧瓶中遇到了属性错误

我有:卸载请求并重新安装了该软件包,安装了该软件包的不同版本,安装了最新的lxml软件包,检查了python PATH。每次使用请求包都是一个错误,但我以与其他运行良好的包相同的方式安装了该请求包。我正在通过pip install运行Python 3.7和最新的请求包

from urllib import request
import random
import requests
import urllib
import time
from datetime import date
import sys
import re
import json
from flask_wtf import FlaskForm
from bs4 import BeautifulSoup
from flask import Flask, render_template, jsonify


@app.route("/handle_data", methods =['GET', 'POST'])
def handle_data():
    if requests.methods == 'POST':
        userName = requests.form.get['username']
        listName = requests.form.get['listname']

                code here
HTML
<!-- Forms -->
<form action="{{ url_for('handle_data') }}" method="POST">
<form>
  <div class="form-row">
    <div class="col">
      <input type="text" size=15 name=username class="form-control" placeholder="Username">
     </div>
     <div class="col">
      <input type="text" size=15 name=listname class="form-control" placeholder="List Name">
    </div>
  </div>
  <p><input type = "submit" class="buttonclass" value = "Random!" /></p>
</form>

我收到AttributeError。

1 个答案:

答案 0 :(得分:1)

更改

userName = requests.form.get['username']
listName = requests.form.get['listname']

收件人

userName = request.form.get['username']
listName = request.form.get['listname']

请求模块和请求对象(来自烧瓶)被混淆了