webkit2png を使おうとしたら動かない。
エラーは以下の通り。
2017-02-14 17:55:36.413 Python[96859:6854691] Can't open input server /Library/InputManagers/MultiClutchInputManager.bundle Fetching http://auctions.yahoo.co.jp ... 2017-02-14 17:55:36.461 Python[96859:6854754] 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. ... something went wrong: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
動かない理由
El capitan 以降 sierra も、iOSと同じで アプリ側のHTTP の通信がブロックされる、webkit2png はPython で内部的に AppKit を使ってるんドエこの影響を受ける。
対策1
http を使わない
webkit2png http://auctions.yahoo.co.jp/
コレがエラーになるので、HTTPSを使うようにする
webkit2png https://auctions.yahoo.co.jp/
対策2
webkit2png が動かないときは、Configuring App Transport Security に例外を適用する。
このコードを適当なところに書いておく、
from objc import YES
from AppKit import NSBundle
bundle = NSBundle.mainBundle()
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
info['NSAppTransportSecurity'] = {'NSAllowsArbitraryLoads': YES}
私は、この辺に書いた
34 try:
35 import Foundation
36 import WebKit
37 import AppKit
38 import Quartz
39 import objc
40 ## 2017-02-14 by takuya
41 from objc import YES
42 from AppKit import NSBundle
43 bundle = NSBundle.mainBundle()
44 info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
45 info['NSAppTransportSecurity'] = {'NSAllowsArbitraryLoads': YES}
iOSでHTTPでアクセスできないのは理解できるんだけど、Mac側にもポートされると、ちょっと不自由なOSになりましたね。