Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP address lookup still happens with requests_mock? #238

Open
zhanyuanucb opened this issue Oct 27, 2023 · 1 comment
Open

IP address lookup still happens with requests_mock? #238

zhanyuanucb opened this issue Oct 27, 2023 · 1 comment

Comments

@zhanyuanucb
Copy link

How to prevent calling socket.gethostbyname while using requests_mock?
I still see DNS query sent out even though I mock the url.

Haven't looked into too deep, but I thought the mock adaptor should intercept before IP address lookup?

Here is the code to reproduce
I'm using python3.11

import requests_mock
import requests

url = "https://random.dev"
with requests_mock.Mocker() as m:
	m.get(url, text="test")
	resp = requests.get(url)
	assert resp.text == "test"

And then use tcpdump -i any udp port 53 (may need sudo) to monitor DNS traffic.

@jamielennox
Copy link
Owner

That is interesting - and I would agree, at the point we hook into requests should be well before any DNS resolution happens.

From your snippet and tcpdump though I can't reproduce. There's a decent chance though on my current macbook with some corp settings that there might be like DNS over TLS or other new thing configured, but i do see some DNS traffic.

Can someone else confirm if they see this as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants