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?
Related
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');
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.
I have a simple python script that I want to serve as a website:
import SimpleHTTPServer
import SocketServer
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
I'm in that folder and run
$ python3 -m http.server
then I visit
http://hassbian.local:8000/song.py
The terminal says this and I get the file as a txt file, the script won't execute.
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.1.115 - - [04/Jun/2017 14:19:59] "GET / HTTP/1.1" 200 -
192.168.1.115 - - [04/Jun/2017 14:20:04] "GET /song.py HTTP/1.1" 200 -
Running on a rasberry pi
SimpleHTTPServer doesn't do CGI. If you want CGI you will have to use CGIHTTPServer
This module can run CGI scripts on Unix and Windows systems.
I am not sure if that's what you really want, but invoking a python script in the manner you have shown is CGI. CGI is a really old way of doing things. Running simple web apps with python is now almost exclusively the domain of webapp2 or flask. While more complex apps involving databases are dominated by django.
I have some problem now using zulip dev-env ...
I did success-installation by Dev-env(using run-dev.py in vagrant env) in my Mac PC and then i could access the first-dev page successfully through my mac-pc's browser
But i have been trying to show the first page using Dev-dev in my cloud hosting service (like AWS or google Cloud hosting) for several days
but i could not access and could not show the first page by using global IP and browser
Which part must I change the setting environment?
(that is, I want to access my dev-env[using run-dev.py] by global IP
after that, i want to test... )
Now I am using a cloud hosting. Of course I opened port 9991 and etc...
I use vagrant env and succeed it in cloud host.
In vagrant ssh, I could access zulip by using curl 127.0.0.1:9991 and received a success message:
29/Sep/2016 00:42:04]"GET / HTTP/1.0" 302 0" from running console
but i cannot access it by host console like this
ai2#mrtalk:~/project/zulip$ curl 127.0.0.1:9991
curl: (7) Failed to connect to 127.0.0.1 port 9991: Connection refused
of course , i can't access http://182.162.90.79:9991/ through my pc browser
for this I tried like these
In zproject/dev_setting.py (I changed...these lines)
EXTERNAL_HOST = '0.0.0.0:9991' #orgin localhost but change 0.0.0.0
ALLOWED_HOSTS = ['localhost','182.162.90.79','0.0.0.0'] #orgin localhost but add + '182.162.90.79','0.0.0.0'
In Vagrantfile I changed this line:
config.vm.network "forwarded_port", guest: 9991, host: host_port, host_ip: 127.0.0.1, auto_correct: true
What is wrong with here? Or which part should I change my dev-setting?
I'm going totally crazy here. I'm developing a website using the Python Flask framework and since this afternoon my Linux box is behaving like a mad man. Let me explain.
I've got my Flask website on an Ubuntu 14.04 server. I normally run it using ./run.py file using a virtualenv. Today I installed some packages and finally decided I wanted a clean env again. So I deleted my venv folder and created it again, like a did a million times before:
$ virtualenv venv
$ . venv/bin/activate
(venv) $ pip install -r requirements.txt
# EVERYTHING INSTALLS WITHOUT ERRORS
(venv) $ ./run.py
/home/kramer65/mysite/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
* Running on http://0.0.0.0:5000/
* Restarting with inotify reloader
* Debugger is active!
* Debugger pin code: 219-856-383
/home/kramer65/mysite/venv/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
This is all pretty much as expected. I then proceed to my browser and load my website (also like I did a million times before). The browser loads a very long time, but nothing gets loaded. In the browser console I don't even see any connection opening at all.
I then check the terminal and see nothing happening either. So I stop the dev server using a CTRL+C and get the following output (as expected):
^CException in thread Thread-6:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/home/kramer65/mysite/venv/local/lib/python2.7/site-packages/watchdog/observers/inotify_buffer.py", line 59, in run
inotify_events = self._inotify.read_events()
File "/home/kramer65/mysite/venv/local/lib/python2.7/site-packages/watchdog/observers/inotify_c.py", line 296, in read_events
event_buffer = os.read(self._inotify_fd, event_buffer_size)
KeyboardInterrupt
So I check out any network connections which are open:
$ netstat -tulpn
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 6127/python
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 0.0.0.0:24675 0.0.0.0:* -
udp6 0 0 :::22996 :::* -
So I decide to kill the python process on port 5000 using kill 6127. What then happens just stunns me. The command gets "accepted" (I get no error), but then I see the browser suddenly loads the website and the terminal starts outputting logs:
(venv) $ kill 6127
(venv) $ 83.161.103.21 - - [2016-04-13 13:59:44] "GET / HTTP/1.1" 200 7334 0.045281
83.161.103.21 - - [2016-04-13 13:59:44] "GET / HTTP/1.1" 200 7334 0.062855
83.161.103.21 - - [2016-04-13 13:59:44] "GET / HTTP/1.1" 200 7334 0.080915
83.161.103.21 - - [2016-04-13 13:59:44] "GET / HTTP/1.1" 200 7334 0.099523
83.161.103.21 - - [2016-04-13 13:59:44] "GET / HTTP/1.1" 200 7334 0.118382
83.161.103.21 - - [2016-04-13 13:59:45] "GET /bower/bootstrap/dist/css/bootstrap.min.css?version=3.3.5 HTTP/1.1" 304 745 0.006047
83.161.103.21 - - [2016-04-13 13:59:45] "GET /bower/font-awesome/css/font-awesome.min.css?version=1448904482.0 HTTP/1.1" 304 745 0.003684
etc. etc.
And from this I don't understand anything. I get the output even though I thought I stopped the dev-server using CTRL+C and ran two commands in between (netstat -tulpn and kill 6127).
I can then hit enter a couple times, which gets me my start line again, and then run arbitrary commands:
(venv) $
(venv) $
(venv) $ pwd
/home/kramer65/mysite
(venv) $
and when I reload the website in the browser I simply get the output again in the same terminal window. My commands, any output of my commands, and the Flask dev-server logs just all get outputted in the same terminal window.
I tried rebooting the server, completely removing all website code and removing and installing the virtualenv again, and I even created a new user and installed everything in there, but I get this same result over and over again.
The thing is that I don't know WHY I get this result. Is it because of Flask, because of the virtualenv, because of some weird bug with the network, because of bash or even something else?!
And most importantly, I have no idea how I can solve this. Does anybody have any idea? All tips are welcome, because I'm pulling out my hair here..
[EDIT]
I ran $ ps -eaf | grep python, with the following results:
$ ps -eaf | grep python
immotest 1489 1444 0 14:33 pts/1 00:00:00 venv/bin/python ./run.py
immotest 1497 1489 1 14:33 pts/1 00:00:00 /home/kramer65/mysite/venv/bin/python ./run.py
immohie+ 1510 1374 0 14:34 pts/0 00:00:00 grep --color=auto python
I already suspected it had something to do with the Flask dev server which spawns a new process to be able to restart itself upon code changes. I had added watchdog to requirements.txt because I use it to sync code from my laptop to my Linux dev server.
The Flask dev server works with Watchdog, but for some reason on this machine it wasn't. After removing watchdog from the server everything works fine again. I wasn't able to isolate the problem with a minimal Flask application.