我有以下从ovh-rest gem 中提取的代码:
method = :get
@api_url = "https://api.ovh.com/1.0"
@api_key, @api_secret, @consumer_key = "123456789", "abcdef", "ghijkl"
endpoint = "/ip/123.456.678/"
url = @api_url + endpoint
uri = URI.parse(url)
body = nil
ts = Time.now.to_i.to_s
sig = "$1$" + Digest::SHA1.hexdigest("#{@api_secret}+#{@consumer_key}+#{method.upcase}+#{url}+#{body}+#{ts}")
request_uri = uri.path
request_uri += '?' + uri.query if uri.query
request = Net::HTTP.const_get(method.capitalize).new(request_uri)
request["X-Ovh-Application"] = @api_key
request["X-Ovh-Consumer"] = @consumer_key
request["X-Ovh-Timestamp"] = ts
request["X-Ovh-Signature"] = sig
request["Content-type"] = "application/json"
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.request(request)
JSON.parse(response.body)
如果我一步一步做所有事情,我会遇到以下错误:
{
"errorCode": "QUERY_TIME_OUT",
"httpCode": "400 Bad Request",
"message": "Query out of time"
}
但是如果我在做之前等待几秒钟(可变持续时间)response = http.request(request)
,我有一个成功的请求:
{
"organisationId": "nil",
"country": "myCountry",
"routedTo": {
"serviceName": "somename"
},
"ip": "123.456.678/32",
"canBeTerminated": true,
"type": "failover",
"description": "nil"
}
我不知道问题是来自我的服务器(ruby 进程到高以快速响应)还是来自其他地方..
重要的提示 :
这段代码就像一个魅力,但几天前......停止工作。