我试图从Sanic中的传入请求中获取推荐网站URL/服务器名(而不是IP地址)。但是,到目前为止,我已经设法从请求头获得连接的IP和端口。Sanic中有任何python包或内置功能吗?
发布于 2019-07-23 11:44:24
试试这个:
referrer = request.headers.get("Referer") # url
u = urlparse(referrer)
print(u.netloc) # server name引用标头的文档- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer
用于urlparse - https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse的文档
https://stackoverflow.com/questions/57071501
复制相似问题