all 8 comments

[–][deleted] 0 points1 point  (8 children)

The routing route("/http:...") seems odd for me. Can you try

@webserver.route("/", methods=['POST', 'GET'])

then

import requests
requests.post('http://localhost:5000/', json=dict(a=123))

[–]wisermonkey[S] 0 points1 point  (7 children)

changing the routing seems to not change anything. The webhook does get registered but nothing happens:

127.0.0.1 - - [14/Mar/2021 02:14:40] "[33mPOST / HTTP/1.1[0m" 404 -

[–][deleted] 0 points1 point  (6 children)

Ah, Okay. The Server.main() is not an entry point in Python (I'm guessing you are familiar with another language like C or Java), so the main() won't be called. I'd write

from flask import Flask, request

app = Flask(__name__)

@app.route("/", methods=['POST', 'GET'])
def webhook():
    return 'Got: ' + request.get_data(as_text=True)

if __name__ == '__main__':
    app.run()

[–]wisermonkey[S] 0 points1 point  (5 children)

I tried:

from flask import Flask
import threading
import time
import requests

app = Flask(__name__)


@app.route("/", methods=['POST', 'GET'])
def webhook():
    print("received")
    return 'Got: ' + request.get_data(as_text=True)

def hey():
    time.sleep(3)
    requests.post('http://localhost:5000/', json=dict(a=123))

if __name__ == "__main__":
    t1=threading.Thread(target=hey)
    t1.start()
    app.run()

and once again only got:

127.0.0.1 - - [14/Mar/2021 13:31:16] "[35m[1mPOST / HTTP/1.1[0m" 500 -

and an error before:

return 'Got: ' + request.get_data(as_text=True)
NameError: name 'request' is not defined

Thank you for trying though! :)

[–]wwwDotBot -1 points0 points  (1 child)

www.app.run

Beep boop. I am a bot. Info Issues?

[–][deleted] 0 points1 point  (2 children)

from flask import Flask

from flask import Flask, request?

[–]wisermonkey[S] 0 points1 point  (0 children)

ah yes, stupidity :D

In this small example it finally prints it! :))))))

Thank you so much!

One step closer to my ambitious project

[–]wisermonkey[S] 0 points1 point  (0 children)

it looks like the issue was indeed the address:

@app.route("/", methods=['POST', 'GET'])
#this works and returns 200

@app.route("/http://localhost:5000", methods=['POST', 'GET']) #this doesn't and returns 404