Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

python - AttributeError: module 'requests' has no attribute 'post'

I got this error, but the issue is that I did not named my py file as "requests.py", so changing file's name did not solve it. But I have a requests folder and a file named "bot.py"

import requests

def lambda_handler(event,context):
        print(event)
        send_message(event["message"]["from"]["id"], event["message"]["text"])

def send_message(chat_id, text):
        url = "https://api.telegram.org/bot{token}/{method}".format(
                token="",
                method="sendMessage"
        )
        data = {
                "chat_id": chat_id,
                "text": text
        }
        r = requests.post(url, data=data)
        print(r.json())

def start_requests():
        url = "https://api.telegram.org/bot{token}/{method}".format(
                token="",
                method="setWebhook"
        )
        data={
                "url": "https://zglp665ptf.execute-api.us-east-2.amazonaws.com/v0/Zerozez_ntf_bot"
        }
        r=requests.post(url,data=data)
        print(r.json())

if __name__=="__main__":
        start_requests()

It also shows these errors:

Traceback (most recent call last):
  File "/var/task/bot.py", line 5, in lambda_handler
    send_message(event["message"]["from"]["id"], event["message"]["text"])
  File "/var/task/bot.py", line 16, in send_message
    r = requests.post(url, data=data)

Am I missing something here?

question from:https://stackoverflow.com/questions/65916746/attributeerror-module-requests-has-no-attribute-post

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do you install requests and import it?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...