I've tried to host my Flask to Heroku so someone can send JSON data to it but the runtime is too big and the app crashes but on my local host it works(although does take a bit). I want to try and run my Flask from my localhost and someone can ping my app somehow to send me JSON data. I've used my server before for discord bots that other people can use, while I have it running at least. Is it possible to do something similar with a Flask app? Someone is using PHP and needs to ping my Flask with JSON.
Asked
Active
Viewed 41 times
0
-
1It is possible. There is a warning about not running the Flask built-in webserver in production, though, so if you're going to heed that warning you'll need to setup and run something like Nginx or Apache to serve your application. – mechanical_meat Apr 17 '21 at 20:00
-
@mechanical_meat It is for a school project, so only going to really be used when we test it and when we present the project to the class. How do I go about doing this? – Zea R Apr 17 '21 at 20:04
-
flask can be accessed through the same wifi though! not tried over same VPN like school network though. – simpleApp Apr 17 '21 at 20:11
-
1@ZeaR: you can specify to `app.run()` command to be accessible to other machines like: `app.run(host='0.0.0.0',port=5000)`. Be aware that you may have firewall software that is not allowing such access, though. There should be a way to open up a port in that software. Another potential issue is that you may have a dynamic IP address which changes every so often. You would probably want to accept connections from only a certain IP range, as well, if you can get that info from your client/collaborator. – mechanical_meat Apr 17 '21 at 20:18
-
@mechanical_meat So i do that and I get this error: Warning: Silently ignoring app.run() because the application is run from the flask command line executable. Consider putting app.run() behind an if name == "main" guard to silence this warning. app.run(host='0.0.0.0',port=5000) ... then i do put it in that if statement and my def is named __main__() but nothing happens – Zea R Apr 17 '21 at 21:34
-
1Oh, don't name your function `__main__` because that's something Python is using... I presume that's the issue. You can call your function anything else that you want. – mechanical_meat Apr 17 '21 at 23:41
-
@mechanical_meat oh alright thanks. Ran flask run - h 192.xxx.x.xxx from my command line and it worked but my partner from outside my network still wasnt able to access so I guess I am at a loss – Zea R Apr 18 '21 at 01:14
-
1The 192.xxx.x.xxx IP address is an internal one only available within your LAN. Use `flask run --host=0.0.0.0` to open access to external connections. Documentation here: https://flask.palletsprojects.com/en/1.1.x/quickstart/?highlight=externally%20visible – mechanical_meat Apr 18 '21 at 02:49
-
@mechanical_meat okay nice i got it to run and can access it locally. Last question and ill stop bothering you hopefully. How would someone outside of my network send JSON data to the server now? I assume http://0.0.0.0:5000/ wont work for them since they're outside. Would they need my ip address and put it as part of it somehow? – Zea R Apr 18 '21 at 04:58
-
Yes, your externally facing IP and the port; like this: 'http://52.11.21.43:5000/your_endpoint', and they should know how to send JSON in PHP hopefully. – mechanical_meat Apr 18 '21 at 12:20
-
@mechanical_meat so I used "flask run --host=0.0.0.0" and then to test it in postman I typed '52.11.21.43:5000/72.63.xxx.xx' the ending being my ipv4, I even edited my router settings to accept inbound requests to ipv4. My requests are still being timed out when I try to process. Am I typing in something wrong? I tried both '52.11.21.43:5000/72.63.xxx.xx' and 'http://52.11.21.43:5000/72.63.xxx.xx' both got timed out – Zea R Apr 18 '21 at 17:49
-
1Oh no, I'm sorry. I just typed that IP as an example. Use your 72.63.xxx.xx in place of the IP I typed, and it should work. – mechanical_meat Apr 18 '21 at 17:55
-
@mechanical_meat no luck. Guess it doesnt work for my computer. It says "running on http://0.0.0.0:5000/" in my flask and then I try to send the POST to "72.63.xxx.xx:5000/" and still get either a timeout or 'connect ECONNREFUSED 72.63.xxx.xx:5000' Thanks for all your help tho, I appreciate it – Zea R Apr 18 '21 at 18:24