HTTP server not working (Python)

This is my first time trying to get HTTP servers working on my computer, so I ran into several technical difficulties.

I am using Python to develop a server and I can access it on my localhost. But when I try to connect via IP it doesn't work. I tried to connect to the phone too and it didn't work. In my opinion, I can connect to the server, but others cannot. I have disabled Windows Firewall and it still doesn't work. Here is my code:

import SimpleHTTPServer
import SocketServer

handl = SimpleHTTPServer.SimpleHTTPRequestHandler
s = SocketServer.TCPServer(("localhost",2138),handl)
s.serve_forever()

      

If it matters, I had the same problem with WAMP Server. I turn off the firewall and start it and I can't connect to other devices. Moreover, I tried it in a different house on a different router and it still didn't work. However, I can connect to my own WAMP server.

I really don't understand what is going wrong and I would appreciate it if someone could help me!

+3


source to share


4 answers


It looks like your router is blocking you. You need to open the configuration page of your router, usually 192.168.1.1 or something similar, check your router manual. Then you need to configure it to port the port to your server PC. The step for this varies from router to router, try translating "your_router_here port forwarding" without quotes, replace your_router_here with the router you are using.



+2


source


Please change "localhost"

to the public IP address of your network adapter and try again.



First of all, you need to ping through it to ensure that the data line is clear. Then try visiting it.

+2


source


You can change "localhost" to "0.0.0.0" to listen to all IP addresses you have. This is the easiest way to expose the service to other hosts.

+2


source


adding a public IP worked for me, although you can try adding "0.0.0.0" to bind it to all interfaces if there is any problem with the interface you are binding to.

+1


source







All Articles