Skip to content

How to get server IP from Httpx get response #2633

Closed Answered by tomchristie
ElliotGarbus asked this question in Q&A
Discussion options

You must be logged in to vote

Is there a better way?

There is a better way, yes...

That answer is digging into private API, so don't expect it to be resilient.

We do provide a response extension which gives a public API onto this information.
It is currently only documented in the low level httpcore library docs, here... https://www.encode.io/httpcore/extensions/#extra-network-information
But we should also document it, since it's available through httpx too.

See issue #2599

Adapting your example to include the server address info...

import httpx

with httpx.Client() as client:
    with client.stream("GET", "https://httpbin.org/get") as response:
        network_stream = response.extensions["network_stream"]
        s…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@tomchristie
Comment options

@robe1149
Comment options

Answer selected by tomchristie
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants