Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask check where a request comes from

I'm new to flask and am trying to find out where certain HTTP requests are coming from. I have an API sending out requests to my server and I need to verify it was my API and not some random post. How can I check where an HTTP request comes from?

like image 316
Josh Carter Avatar asked Oct 24 '25 17:10

Josh Carter


1 Answers

Flask's request object contains remote_addr, which is the address of the client. Alternatively, request also contains the WSGI environ dictionary, which is defined in PEP 033. In the environ dictionary, there is a REMOTE_ADDR key which contains the same data:

request.remote_addr
request.environ['REMOTE_ADDR']

If you're worried you might be getting data from that IP address, but you still want to form a distinction between your API and some other source, you can include another header in your API's request and access it by the request object

request.headers.get(header_name)
like image 51
awmo Avatar answered Oct 26 '25 06:10

awmo