【问题标题】:Bad syntax in popular python library流行的 python 库中的错误语法
【发布时间】:2018-05-29 13:14:36
【问题描述】:

我正在尝试使用 mitmproxy Python API,但 from mitmproxy import http 行给出了语法错误。 "http" module 包含类似

的行
self.request: HTTPRequest = None

def make_error_response(
        status_code: int,
        message: str="",
        headers: Optional[http.Headers]=None,
) -> HTTPResponse:
    reason = http.status_codes.RESPONSES.get(status_code, "Unknown")

看起来不像 Python。

我是否遗漏了什么,或者这只是糟糕的代码?

【问题讨论】:

  • 这是你需要使用的类型注解python3
  • 您的代码适合我,请确保您使用的是@zimdero 建议的 Python 3

标签: python syntax


【解决方案1】:

mitmproxy docs 中所述,您需要拥有最新的 Python 版本。

请确保为您的发行版安装 Python 3.6(或更高版本)和 pip3。

您看到的是type hints,它已添加到 Python 3.5 中。

【讨论】:

    猜你喜欢
    • 2013-09-09
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2014-07-06
    • 1970-01-01
    • 2010-11-12
    • 2016-09-04
    • 2018-06-08
    相关资源
    最近更新 更多