python - 如何在 Flask 中获取 HTTP 版本

标签 python flask

我想在 flask 中获取 HTTP 版本,如“HTTP/1.1”、“HTTP/1.0”。我检查了请求中的所有 var,但一无所获。

['__class__', '__delattr__', '__dict__', '__doc__', '__enter__', '__exit__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_get_file_stream', '_get_stream_for_parsing', '_is_old_module', '_load_form_data', '_parse_content_type', 'accept_charsets', 'accept_encodings', 'accept_languages', 'accept_mimetypes', 'access_route', 'application', 'args', 'authorization', 'base_url', 'blueprint', 'cache_control', 'charset', 'close', 'content_encoding', 'content_length', 'content_md5', 'content_type', 'cookies', 'data', 'date', 'dict_storage_class', 'disable_data_descriptor', 'encoding_errors', 'endpoint', 'environ', 'files', 'form', 'form_data_parser_class', 'from_values', 'full_path', 'get_data', 'get_json', 'headers', 'host', 'host_url', 'if_match', 'if_modified_since', 'if_none_match', 'if_range', 'if_unmodified_since', 'input_stream', 'is_multiprocess', 'is_multithread', 'is_run_once', 'is_secure', 'is_xhr', 'json', 'list_storage_class', 'make_form_data_parser', 'max_content_length', 'max_form_memory_size', 'max_forwards', 'method', 'mimetype', 'mimetype_params', 'module', 'on_json_loading_failed', 'parameter_storage_class', 'path', 'pragma', 'query_string', 'range', 'referrer', 'remote_addr', 'remote_user', 'routing_exception', 'scheme', 'script_root', 'shallow', 'stream', 'trusted_hosts', 'url', 'url_charset', 'url_root', 'url_rule', 'user_agent', 'values', 'view_args', 'want_form_data_parsed']

另一边,日志有HTTP版本

2013-09-23 06:55:42 208.115.113.85 - - [23/Sep/2013 06:55:42] "GET /robots.txt HTTP/1.1" 404 -

那么,如何在 flask 中获取 HTTP 版本呢?

最佳答案

来自request.environ:

from flask import Flask, request

app = Flask(__name__)

@app.route('/')
def hello():
     return request.environ.get('SERVER_PROTOCOL')

关于python - 如何在 Flask 中获取 HTTP 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18951549/

相关文章:

python - 在 Flask 中的 HTML 页面上打印 python 控制台输出

python - Django 测试用例警告 : Converting column 'options' from VARCHAR to TEXT

python - 将 Flask 环境默认设置为开发模式?

python - 如何通过pi上的边缘检测保存视频录制

python - 如何从 Dataframe 对象字段中提取日期值

javascript - 如何在 flask 中解析此输出?

python - Flask 未在静态文件夹中检测到 .css

python - Flask 路由中的尾部斜杠

python - 无法安装 json2html python 模块

python - 使用 Pandas 自定义排名选择