【问题标题】:Python "app transport security" error under El CapitanEl Capitan 下的 Python“应用程序传输安全”错误
【发布时间】:2015-12-31 04:31:13
【问题描述】:

我的一些 Python shell 脚本在 Apple OSX 10.11、El Capitan 下新出现了安全错误。似乎新的 App Transport Security 不喜欢脚本如何以纯文本形式调用 HTTP 资源,而不是使用 HTTPS。

Fetching http://blahblah.com    
Python[5553:5648168] App Transport Security has blocked a cleartext HTTP (http://) 
resource load since it is insecure. Temporary exceptions can be configured 
via your app's Info.plist file.

我该如何解决这个问题?没有我可以调用的 HTTPS 资源,所以我坚持使用 HTTP。 Apple 的建议是在应用程序的 info.plist 文件中创建一个例外,但这是从 shell 脚本调用的 Python 脚本,因此没有要编辑的 info.plist 文件。

想法?根本问题似乎出在 Python 中的 webkit2png 上。其非 HTTPS 请求被 ATS 拦截,没有 info.plist 可修改。

【问题讨论】:

    标签: python macos shell


    【解决方案1】:

    感谢亚瑟赫伯特

    起初我对代码感到困惑,然后我弄清楚了

    所以我总结如下步骤供参考

    1. import AppKit

    2. 在您的 py 脚本中添加以下代码 AppKit.NSBundle.mainBundle().infoDictionary()['NSAppTransportSecurity'] = dict(NSAllowsArbitraryLoads = True)

    假设您确定在高于 10.11 的 MAC OSX 中不使用 HTTPS 资源

    在我的情况下不需要安装 webkit2png

    【讨论】:

      【解决方案2】:

      我在这里找到了适合我的解决方案:https://apple.stackexchange.com/questions/210588/how-does-one-configure-a-temporary-exception-to-ats-on-el-capitan-and-fix-webkit

      首先确保您的webkit2png 版本足够新,可以使用--ignore-ssl-check 选项。 0.5 版没有这个选项。

      其次,您需要编辑源文件并添加几行代码,如下所示:https://github.com/bendalton/webkit2png/commit/9a96ac8977c386a84edb674ca1518e90452cee88

      最后使用上面链接的解决方案中指示的选项(为方便起见,在此处复制):

      webkit2png --ignore-ssl-check [options] [http://example/]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        • 2018-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-16
        相关资源
        最近更新 更多