【发布时间】:2026-01-07 01:30:01
【问题描述】:
Python 版本:3.5.1
请求版本:2.9.1。
我正在尝试获取 python 请求中 url 的 IP 地址,如下所述:How do I get the IP address from a http request using the requests library?
import requests
rsp = requests.get('http://google.com', stream=True)
# grab the IP while you can, before you consume the body!!!!!!!!
print (rsp.raw._fp.fp._sock.getpeername())
# consume the body, which calls the read(), after that fileno is no longer available.
print (rsp.content)
出现以下错误:
AttributeError: '_io.BufferedReader' object has no attribute '_sock'
可能是一些版本问题。请帮忙。
附:无法在原始帖子中发表评论。
【问题讨论】: