I am doing experiments with requests trough proxy for web-scraping project. In order to test requests headers and content i’ve build a simple flask server like this:
from flask import Flask from flask import request app = Flask(__name__) @app.route("/") def index(): ret_str = f'<- {request} ->n' f'<----- HEADERS ----->n' f'{request.headers}n' f'<----- DATA ----->n' f'{request.data}n' print(ret_str) return ret_str if __name__ == "__main__": app.run(host='0.0.0.0', port=5000)
Which is run perfectly fine if access through localhost by 127.0.0.1:5000 (with app.run()
) and through local network by requesting the local address 10.214.14.222:5000 (which is displayed by ipconfig).
But if i try to access it through my 4G connection or through proxy, request fails. According to https://ipchecker.io/, my outside ip is, let’s say 216.94.151.186, but requesting my page using 216.94.151.186:5000 gives ‘page not found’.
How to access the test server from outside the local network? Can anyone please help?
SOLUTION: Set up port forwarding on router and make computer that run flask server IP-address static on router.
Advertisement
Answer
What you’ll need to do is make your specified port available on your router. This is done with port forwarding. The location of this tab can switch depending on your router provider but once this is done you can just visit This link which shows your public IP. Then you can just visit: 000.00.000.00:5000 <– Replace zero’s with public IP.