问题描述
是否有使用任何标准 python 库向 url 发出 HTTP GET 请求的标准方法,主要警告是主机地址是 ipv6 链接本地地址(重点强调链接本地")?运行服务器的目标机器除了包含 mac 地址的原始链接本地 ip 地址之外没有任何 ip 地址(因此只能通过类似于fe80::%eth0"的地址访问它其中%eth0"是与服务器共享广播域的客户端上的网络接口).
Is there a standard way to issue an HTTP GET request to a url using any standard python library, with the major caveat that the host address is an ipv6 link-local address (heavy emphasis on "link-local")? The target machine that is running the server does not have any ip address other than the raw link-local ip address that includes the mac address (hence it can only be reached by an address that looks something like "fe80:::%eth0" where "%eth0" is the network interface on the client that shares a broadcast domain with the server).
推荐答案
您可以使用 Twisted 的 HTTP 客户端 API:
from __future__ import print_function
from sys import argv
from twisted.internet.endpoints import TCP6ClientEndpoint
from twisted.web.client import ProxyAgent
from twisted.internet.task import react
def main(reactor, address, uri):
server = TCP6ClientEndpoint(reactor, address, 80)
agent = ProxyAgent(server, reactor)
getting = agent.request(b"GET", uri)
def got(response):
print("Got {}".format(response.code))
getting.addCallback(got)
return getting
if __name__ == "__main__":
react(main, argv[1:])
例如:
$ python http-proxy-get.py ::1 http://example.com/
Got 200
$
这篇关于在python中,向ipv6链接本地地址发出get请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!