Python 属性错误:模块';请求';没有属性';发布';。它是否已被弃用并引入了新功能?

Python 属性错误:模块';请求';没有属性';发布';。它是否已被弃用并引入了新功能?,python,rest,flask,python-requests,localhost,Python,Rest,Flask,Python Requests,Localhost,我一直在尝试向使用flask构建的本地服务器发送请求。 使用python的requests模块发送请求 我不知道该requests.post函数是否已被弃用并引入了新函数,或者我的代码是否真的有问题。我所做的一切都完全如中所说。 这是我的密码: import requests host_url = "http://127.0.0.1:5000" # get the data data_for_prediction = [int(input()) for _ in range(10)] r =

我一直在尝试向使用flask构建的本地服务器发送请求。 使用python的
requests
模块发送请求

我不知道该
requests.post
函数是否已被弃用并引入了新函数,或者我的代码是否真的有问题。我所做的一切都完全如中所说。
这是我的密码:

import requests

host_url = "http://127.0.0.1:5000"

# get the data
data_for_prediction = [int(input()) for _ in range(10)]
r = requests.post(url=host_url,json={data_for_prediction})
print(r.json())
以上代码的错误是:

Traceback (most recent call last):
  File "C:/Users/--/requests.py", line 1, in <module>
    import requests
  File "C:\Users\--\requests.py", line 8, in <module>
    r = requests.post(url=host_url,json={data_for_prediction})
AttributeError: module 'requests' has no attribute 'post'

Process finished with exit code 1
我尝试了检查文档,在线检查了许多文章,还重新编写了整个代码。但是,没有任何帮助


那么,这是不是
requests.post
函数已被弃用并引入了一个新函数,或者我的代码有什么问题。

您似乎正在将代码写入名为
requests.py
的文件中,因此当您尝试导入requests模块时,它会将您自己的文件作为模块导入。尝试重命名您的文件…

我真是太蠢了,没有检查名称。谢谢。(请不要在回答问题后故意破坏它-我们非常希望保留问题,因为它们是根据页脚中的许可条件提出的)。
flask_server_app = Flask(__name__)

# let's make the server now
@flask_server_app.route("/api/predict", methods=["GET", "POST"])
# my prediction function goes here
def predict():
    # Get the data from the POST request & reads the received json
    json_data = request.get_json(force=True)

    # making prediction
    # Make prediction using model loaded from disk as per the data.
    prediction = ml_model.predict([[json_data]])

    # return json version of the prediction
    return jsonify(prediction[0])

# run the app now
if __name__ == '__main__':
    flask_server_app.run(port=5000, debug=True)