requests-mock icon indicating copy to clipboard operation
requests-mock copied to clipboard

IP address lookup still happens with `requests_mock`?

Open zhanyuanucb opened this issue 9 months ago • 1 comments

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.

zhanyuanucb avatar Oct 27 '23 03:10 zhanyuanucb