python -m SimpleHTTPServer no longer working - python

python -m SimpleHTTPServer 8000 was working fine in order to render my web pages on localhost. When it quit, I used 7800, which also failed eventually, and now no numerical string works. For example, having launched the server using python -m SimpleHTTPServer 7600, I get the following when trying to render through the browser (any browser):
Serving HTTP on 0.0.0.0 port 7600 ...
127.0.0.1 - - [21/Feb/2022 20:14:04] code 404, message File not found
127.0.0.1 - - [21/Feb/2022 20:14:04] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [21/Feb/2022 20:14:19] code 404, message File not found
127.0.0.1 - - [21/Feb/2022 20:14:19] "GET /FrontandBackMatter/css/style.css HTTP/1.1" 404 -
I get this result having changed nothing in the files.

Related

Flutter Web and logging on iPhone

I have a Flutter Web app with an iOS Safari-specific error. To debug it I create a build (flutter build web) and run Python's http.server (python3 -m http.server), then use ngrok to be able to open the app on my mobile device.
To be able to see logs I use OverlayEntry with Text, but it's not very convenient.
Python's http.server does some logging that looks like this:
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
::1 - - [10/Sep/2022 20:05:06] "GET / HTTP/1.1" 200 -
::1 - - [10/Sep/2022 20:05:07] "GET /flutter.js HTTP/1.1" 304 -
Is it possible to log something from a Flutter app to see it inside Python's http.server logs?
Yes, it's possible. You can use print() to log something to the console. You can also use the dart:developer package to log to the browser's console. Example:
import 'dart:developer' as developer;
developer.log('Hello world!', name: 'my.app.category');

flask.cli.NoAppException: Failed to find Flask application or factory in module "flaskr". Use "FLASK_APP=flaskr:name to specify one

I am building a python web application using flask and following tutorial from http://flask.pocoo.org/docs/1.0/tutorial/factory/ . I am running the flask from the parent directory but getting following error.
(venv) E:\python-code\python-web>flask run
* Serving Flask app "flaskr" (lazy loading)
* Environment: development
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 294-690-396
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello HTTP/1.1" 500 -
Traceback (most recent call last):
File "e:\python-code\python-web\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "e:\python-code\python-web\venv\lib\site-packages\flask\cli.py", line 95, in find_best_app
module=module.__name__
flask.cli.NoAppException: Failed to find Flask application or factory in module "flaskr". Use "FLASK_APP=flaskr:name to specify one.
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:44] "GET /hello?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:44] "GET /hello?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
Please help.
I have tried Running Flask app from cli gives "no module named flaskr"
and
flask.cli.NoAppException: Failed to find application in module?
I have found my problem. I was missing return app as the last statement in my code. Sorry for confusion and apologies.
I got that error
flask.cli.NoAppException flask.cli.NoAppException: Failed to find
Flask application or factory in module "flaskr". Use
"FLASK_APP=flaskr:name to specify one.
I tried all answers, and it got resolved after I changed the function name from create_function to create_app
I followed the instructions just like the official tutorial said but still got the same error.
My problem was with the IDE that I was using ( Pycharm )
Even though I had an init.py file in the flaskr directory, it still wasn't considered as a package.
So I deleted the flaskr directory and created a "new package". Then just copy the code in the init.py and that'll solve the problem
is your application dir not named properly? for example, if you wrote FLASK_APP=flaskr but your project name is something else, you will get this error. Also, what is in your flaskr/flaskr/__init__.py file if the project is named flaskr like in the tutorial?
You can't name the FLASK_APP enviroment var as Flask.py. Try with another name please and try again.
No puedes poner el nombre de la variable de ambiente FLASK_APP como Flask.py. Prueba cambiando el nombre del archivo.
Depending on the OS you are using you need to export flaskr in your environment
For Linux and Mac:
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run
For Windows cmd, use set instead of export:
set FLASK_APP=flaskr
set FLASK_ENV=development
flask run
For Windows PowerShell, use $env: instead of export:
$env:FLASK_APP = "flaskr"
$env:FLASK_ENV = "development"
flask run```

Flask can't find/run my app even though its in my Pythonpath

I have a very simple Flask app setup locally but when I try to run it I get this error:
NoAppException: The file/path provided (cowork_map) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py
Im in a virtual env with flask and all other requirements installed and up to date, I have added the path to my project folder to my $PYTHONPATH and have checked that its there.
I have also used the second answer here to force check if its in my sys.path:
How to add something to PYTHONPATH?
I have tried force running it with 'python -m flask run' as advised here
Flask can't find app file
I ran export 'FLASK_APP=myapp.py' as advised in the official docs.
I have also tried running with with 'FLASK_DEBUG=1' and this is the output:
127.0.0.1 - - [05/Mar/2017 16:55:13] "GET /? __debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [05/Mar/2017 16:55:13] "GET /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [05/Mar/2017 16:55:13] "GET /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [05/Mar/2017 16:55:13] "GET /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
127.0.0.1 - - [05/Mar/2017 16:55:13] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [05/Mar/2017 16:55:13] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
Whats even stranger is that I have another Flask project folder with its own env and that runs just fine, I can't see whats different with this one though.
I should add that everything in my app file is setup correctly with a Flask app initialized.
Also, if I run 'python -mflask run' (with DEBUG on) I get this error on the page when viewed locally:
__main__.NoAppException
but just 'flask run' displays this:
flask.cli.NoAppException
OK I figured this out, I have both Python 2.7 and 3 on my machine and there was a module I had imported that was installed on the other version of Python to the one I was using in my env. A very noob error I suppose!

PC name display for SimpleHTTPServer

When I run python -m SimpleHTTPServer <port> on my office network, I can get my full PC name displayed in the log output.
Serving HTTP on 0.0.0.0 port 59992 ...
<pc name> - - [04/Feb/2014 04:59:30] "GET / HTTP/1.1" 200 -
But when I run the same in my home network or locally host it, the logs only display the IP address which accessed the service.
Serving HTTP on 0.0.0.0 port 59992 ...
<my ip> - - [04/Feb/2014 04:59:30] "GET / HTTP/1.1" 200 -
Is there any way I could make my home network do the same?

Django not picking up new changes

I'm running an old branch A from my GitHub repo, and Django is not picking up any of the static files. What's weird is that if I make any text changes to the templates, it doesn't pick those up either. I've tried refreshing the page, opening Chrome in Incognito, restarting the server, etc. -- nothing is working.
After running the development server in a different branch B, and switching back to this one, Django acted as if I was still running on branch B (got not 404 errors):
$ ./manage.py runserver
0 errors found
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[12/Sep/2012 23:25:48] "GET /interviews/ HTTP/1.1" 200 13295
But as soon as I restarted the server, it reverted to the un-changed version of branch A (none of the changes were picked up and no static files could be found):
$ ./manage.py runserver
Validating models...
0 errors found
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[12/Sep/2012 23:26:20] "GET /interviews/ HTTP/1.1" 200 13295
[12/Sep/2012 23:26:20] "GET /static/js/plugins.js HTTP/1.1" 404 2653
[12/Sep/2012 23:26:20] "GET /static/js/jquery-1.7.1.min.js HTTP/1.1" 404 2653
[12/Sep/2012 23:26:20] "GET /static/css/style.css?v=2 HTTP/1.1" 404 2653
[12/Sep/2012 23:26:20] "GET /static/js/script.js HTTP/1.1" 404 2653
Between the two branches, settings.py and the static folder are identical so I'm not even sure where to begin with troubleshotting.
DEBUG = True
Check this. Built-in Django dev server does not work with static files if DEBUG = False.

Categories

Resources