【发布时间】:2016-12-20 21:31:20
【问题描述】:
我正在编写一个 go appengine 应用程序,它需要从 Stripe 获取页面。
基本上我使用的是官方 Stripe API 附带的these instructions。但是,当我使用 dev_appserver.py 运行它时,我得到:
2016/08/14 12:03:15 Requesting POST api.stripe.com/v1/customers
2016/08/14 12:03:18 Error encountered from Stripe: {"type":"invalid_request_error","message":"Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at https://stripe.com/blog/upgrading-tls.","request_id":"req_90O6reF1Mwi9yZ","status":401}
我发现 Python AppEngine 应用程序可以在我的 app.yaml 中指定要使用的 SSL 库(请参阅 SSL support)。但是,如果我在 app.yaml 文件中添加 libraries 部分,我会得到:
$ (go_appengine/dev_appserver.py app)
Traceback (most recent call last):
File "go_appengine/dev_appserver.py", line 89, in <module>
_run_file(__file__, globals())
File "go_appengine/dev_appserver.py", line 85, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1040, in <module>
main()
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 1033, in main
dev_server.start(options)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 758, in start
options.config_paths, options.app_id)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 831, in __init__
module_configuration = ModuleConfiguration(config_path, app_id)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 127, in __init__
self._config_path)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 424, in _parse_configuration
config, files = appinfo_includes.ParseAndReturnIncludePaths(f)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/appinfo_includes.py", line 82, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/appinfo.py", line 2191, in LoadSingleAppInfo
listener.Parse(app_info)
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/yaml_listener.py", line 227, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "/Users/kchodorow/gitroot/tt/go_appengine/google/appengine/api/yaml_listener.py", line 178, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: libraries entries are only supported by the "python27" runtime
in "app/app.yaml", line 25, column 1
这是有道理的,因为我没有使用 Python。我真的需要一种方法来为 Go 设置它。
我的 app.yaml 文件如下所示:
application: app-name
version: alpha-001
runtime: go
api_version: go1
handlers:
...
将 runtime 更改为 python27 可以消除库错误,但显然我的 go 代码不起作用。
知道如何通过开发应用服务器和生产启用 TLS 1.2?
【问题讨论】:
-
您不能在 appengine 上创建传输吗?像
tr := &http.Transport{ TLSClientConfig: &tls.Config{...}, } client := &http.Client{Transport: tr}可能在 flex 环境中? -
不幸的是,AppEngine 要求您使用它的传输,urlfetch.Transport (AFAICT)。可能有一些方法可以覆盖这个传输的RoundTrip 正在做的事情,这就是我正在寻找的建议。
-
我认为可以在flex environment 上完成 - 请参阅here
-
啊哈!根据您对传输的建议,我深入研究了 RoundTrip 代码调用的内容,最终发现我可以使用普通的 http.Client,我只需要在传输中设置
Proxy: http.ProxyFromEnvironment。如果你想写一个答案,很高兴奖励你。 -
是的,现在只使用
&http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12,},},},不需要弄乱 urlfetch。我不知道为什么http.Client最初是不允许的。
标签: google-app-engine ssl go