我正在编写一个 go appengine 应用程序,它需要从 Stripe 获取一个页面。
基本上我用的是these instructions随官方 Stripe API 一起提供。但是,当我使用 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)。但是,如果我将 libraries
部分添加到我的 app.yaml 文件中,我会得到:
$ (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 有什么想法吗?
最佳答案
来自 Go net/http 文档:
For control over proxies, TLS configuration, keep-alives, compression, and other settings, create a Transport:
tr := &http.Transport{
TLSClientConfig: &tls.Config{...},
DisableCompression: true,
}
client := &http.Client{Transport: tr}
来自appengine documentation看起来您可以像往常一样使用 net/http 包并进行一些调整。
关于google-app-engine - 如何在 Go AppEngine 应用程序中将 TLS 1.2 与 appengine/urlfetch 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38942171/