python - 在Python中处理get请求

标签 python html get

如何使用发送get请求的客户端的IP地址? 我的目标是为每个客户端创建唯一的文件,其中文件将被命名为客户端的 IP 地址。抱歉,我已经有一段时间没有使用 Python 了。

最佳答案

阅读文档。如果您计划使用标准库 HTTPServer,您可以看到它将在处理程序中向您发送客户端地址:

BaseHTTPRequestHandler

class BaseHTTPServer.BaseHTTPRequestHandler(request, client_address, server)
This class is used to handle the HTTP requests that arrive at the server. By itself, it cannot respond to any actual HTTP requests; it must be subclassed to handle each request method (e.g. GET or POST). BaseHTTPRequestHandler provides a number of class and instance variables, and methods for use by subclasses.

The handler will parse the request and the headers, then call a method specific to the request type. The method name is constructed from the request. For example, for the request method SPAM, the do_SPAM() method will be called with no arguments. All of the relevant information is stored in instance variables of the handler. Subclasses should not need to override or extend the init() method.

...
client_address:
Contains a tuple of the form (host, port) referring to the client’s address.

SimpleHTTPRequestHandler

class SimpleHTTPServer.SimpleHTTPRequestHandler(request, client_address, server)

关于python - 在Python中处理get请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13504929/

相关文章:

c# - 序列化从 CLR 类型继承的 IronPython 对象

html - 保留 CSS 动画中的最后一个关键帧属性

javascript - Netbeans Web应用程序错误404包含js

html - 如何正确对齐 CSS/bootstrap 中的段落?

php - 通过 CURL 获取 Instagram 数据

python - 每次发布请求时都会重新加载静态样式表

Python 安装 python-ntlm-1.0

python - 在 Meteor 中调用 Python 脚本

python - 对 NumPy 数组求和 SymPy 表达式

html - 如何在 bootstrap 3 中更改整行悬停时的 bg 颜色