Inability to view my flask application on the web - python

I have been working on a flask application and it has been working just fine. however, for a couple of hours now, i have not been able to run my application on the web. After running the script on command line as usual, i would copy the ip address to my browser in order to display its content but will not respond anymore. I have tried changing port, and other troubleshooting i suppose should work but has still not been able to get it fixed. Any assistance is highly appreciated.
The error message is " this site can not be reached" when is actually running on the server in command line.

Related

Flask flashes appear on development server, but not with uWSGI/Nginx

I have been learning Flask by making a little website and using the built in flask server that runs with python. I have a page where you press a button, and it flashes a message using the flash system inside of flask. These flashes work fine when I am using the built in flask server on my windows machine. However, I have deployed the website to a Linux server, using uWSGI which goes through Nginx. My issue is that when I access this server, the flashes don't work. Most things like loading pages work fine on both servers, but flashing is broken. I don't see any error messages from uWSGI's logs.
The code I am using for the flash is implemented as follows:
flash("Made new post.")
return redirect(url_for("posts"))
The redirect takes me to the correct page, and if I run a print() statement before the redirect the statements are clearly being reached, the flash just doesn't do anything.
The main other issue I am running into is with sessions and trying to store session variables. Nothing happens when I try to do this either. (but it works on my personal machine)
Any ideas why this might be, or at least a way to get an error message from uWSGI?
To properly set cookies (cookies are what make message Flashing work), both nginx and the Flask application need to agree on the server name.
So make sure your server_name in nginx.conf matches SERVER_NAME (or
SESSION_COOKIE_DOMAIN, if set) in your flask configuration.
There are also limits enforced by nginx on the size of cookies, but this should only be a problem if your flashed messages are really large.

Scapy http_request "Failed to open URL"

Im working on creating a Scapy script that does the three-way handshake, GET request, and then finally grabs the contents of a file via HTTP_request thats on a remote apache server, and then display it in the browser on my machine.
I've managed to get everything working except for when I try to do a HTTP Request it also returns that the file doesn't exist and then shows some random path its looking in.
This is the command ive been tinkering with thats on the scapy site that should work but doesnt:
load_layer("http")
http_request("10.10.10.10","/test", port=80, display=True)
the permissions of the files on the remote host are 777 just for testing
I can reach the web page via Firefox and it displays the file I'm looking for fine (this is just for testing as well)
Tried chrome as well and same issue occurred
information from this command comes back accurate when its without the path, but doesn't open the page either
The error below is the response I continuously get despite different versions of the command. The only difference is that the end of the URL string is different with every run.
i.e: this one is "BSVkz0.html" but the previous one was "WCU4c0.html"
Failed to open URL"file:///tmp/scapyWCU4cO.html".
Error when getting information for file "tmp/scapyBSVkz0.html": No such file or directory.
More info:
played around with it more and received a new error in terminal:
0009:fixme:exec:SHELL_execute flags ignored: 0x00000100 002b:err:winebrowser:wmain Failed to convert file URL to unix path
unsure if that's connected but the two machines involved are both Kali Linux
Any help is greatly appreciated!! thanks in advance

Can someone tell me what's wrong, when I run it the browsers says "This site can’t be reached"

I am learning Python on Treehouse and right now I am on the Flask Turorial. There is a part of how to build a social app. I watched the videos a few times and I typed the exact code in IDLE but when I run the app it runs correctly, then when I type http://127.0.0.1:8090 in the browser it says "The site can't be reached".
Does anyone know where is the problem?
I uploaded my code to GitHub so you can review it. Here's the link: https://github.com/nenadristov/social_app_treehouse/tree/master
Problem is with your Port number. In app.py the Port mentioned is 8000 but you are trying to access 8090.
Try http://127.0.0.1:8000/

using flask in spyder stuck in local server

I am trying to create a web application using flask. I have already gotten somewhat comfortable with using python, and have done so using spyder, inside of Anacanda Navigator. Now I am playing around with flask doing basic functions and have successful so far by testing it out in local server 127.0.0.1:5000. The problem I am having is that I cannot stop the server once I run the script in spyder. I have stopped the script and run other scripts through the console, but the local server remains the same.
The reason this is a problem for me is because when I try to change files and run a different flask script, the server does not update with the new information. For example, if I run a flask script that returns "Hello World" on the main page, and then I stop that file, open a new file that has a different flask script that returns "The sky is blue" the server does not change when I check it on chrome or any other browser. It will onyl return "Hello World"
I have been able to fix this problem by completely restarting my computer, but I am wondering if there is another way, just to restart the local server, 127.0.0.1:5000. Thank You!
Also I am using windows
I do : "Run > Configuration per file > Execute in an external system terminal",
then when you run your .py containing the app.run, it will be launched in an external console. If you close the console the server will be closed too.
To Kill the local server, you may use Ctrl+C command and not any other command. This command is also mentioned when the server is up and running.
I've been having this precise issue and have been smashing my head against the wall for a couple of hours. I posted the referenced StackOverflow question (my first actually) and it seems that running a script from inside Spyder is the wrong way to go as it leaves runaway background processes running, even after restarting Spyder.
I got the recommendation to only launch my *.py code from the command prompt. Furthermore I was told to do this:
set FLASK_APP=main1.py then set FLASK_DEBUG=1 then flask run
though I'm not sure what that does, so I will investigate. I was about to restart my computer as a last ditch effort until I looked in my Windows Task Manager and found some Python tasks running. After [end task] them both I was able to launch the updated webpage on my local host.

Running a flask server

So, probably a dumb question, but I am beginning to learn all this so your feedback will be valuable for me.
The question is: In flask documentation it says start the flask server by entering the command 'python hello.py' and I do it successfully to see the output on localhost:5000. Now, I have a shared hosting plan and if I upload this file over there will i need to initiate the server over there as well like this? If so, when I close the terminal over there, will the flask server shut down (because when I close the terminal on my computer it shuts down the flask server and the results are no more available on localhost:5000)?.. It basically suggests me that I have to keep running the terminal all the time..please tell me what is the basic idea here? Thanks.
What you're asking is how you deploy your app. There are many options, that will depend on your needs, your hosting service, etc.
You should check the flask docs for the options. http://flask.pocoo.org/docs/deploying/
In essence, you'll have your flask app running as a local service on the server, so it's not shut down when you close the terminal, and an HTTP server that somehow proxies requests to that service. I guess the most popular is uWSGI with nginx.
When you upload your code to a remote host, you will need to provide a way to start the server and get things running. How this works is host- and software-dependent. As an example, here is some documentation for how you would fire Flask up on Heroku.

Categories