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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With