软层 SDK SoftLayer_Exception_Public: 访问被拒绝
softlayer SDK SoftLayer_Exception_Public: Access Denied
使用 Go SDK
中的示例与用户名和 apikey
返回
{"error":"Access Denied. ","code":"SoftLayer_Exception_Public"}
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"github.com/softlayer/softlayer-go/sl"
)
func main() {
userName := "xxxx"
apikey := "xxxx"
sess := session.New(userName, apikey)
sess.Debug = true
doListAccountVMsTest(sess)
}
func doListAccountVMsTest(sess *session.Session) {
service := services.GetAccountService(sess)
vms, err := service.Mask("id;hostname;domain").Limit(10).GetVirtualGuests()
if err != nil {
fmt.Printf("Error retrieving Virtual Guests from Account: %s\n", err)
return
} else {
fmt.Println("VMs under Account:")
}
for _, vm := range vms {
fmt.Printf("\t[%d]%s.%s\n", *vm.Id, *vm.Hostname, *vm.Domain)
}
}
func handleError(err error) {
apiErr := err.(sl.Error)
fmt.Printf(
"Exception: %s\nMessage: %s\nHTTP Status Code: %d\n",
apiErr.Exception,
apiErr.Message,
apiErr.StatusCode)
}
我在 运行 你的代码时没有遇到问题,我建议检查你发送的用户名和 apikey。请参阅个人资料中的 API 访问信息 部分 https://control.softlayer.com/account/user/profile
值得注意的是,在 IBM 云上并没有很好的文档记录,返回的错误消息也不是很清楚这个事实:有时您收到的拒绝访问错误更多地与以下事实有关:没有升级的 IBM 随用随付帐户。
值得记住这一点,因为其他用户可能 运行 遇到相同的错误消息,但不知道该怎么做。
使用 Go SDK
中的示例与用户名和 apikey
返回
{"error":"Access Denied. ","code":"SoftLayer_Exception_Public"}
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"github.com/softlayer/softlayer-go/sl"
)
func main() {
userName := "xxxx"
apikey := "xxxx"
sess := session.New(userName, apikey)
sess.Debug = true
doListAccountVMsTest(sess)
}
func doListAccountVMsTest(sess *session.Session) {
service := services.GetAccountService(sess)
vms, err := service.Mask("id;hostname;domain").Limit(10).GetVirtualGuests()
if err != nil {
fmt.Printf("Error retrieving Virtual Guests from Account: %s\n", err)
return
} else {
fmt.Println("VMs under Account:")
}
for _, vm := range vms {
fmt.Printf("\t[%d]%s.%s\n", *vm.Id, *vm.Hostname, *vm.Domain)
}
}
func handleError(err error) {
apiErr := err.(sl.Error)
fmt.Printf(
"Exception: %s\nMessage: %s\nHTTP Status Code: %d\n",
apiErr.Exception,
apiErr.Message,
apiErr.StatusCode)
}
我在 运行 你的代码时没有遇到问题,我建议检查你发送的用户名和 apikey。请参阅个人资料中的 API 访问信息 部分 https://control.softlayer.com/account/user/profile
值得注意的是,在 IBM 云上并没有很好的文档记录,返回的错误消息也不是很清楚这个事实:有时您收到的拒绝访问错误更多地与以下事实有关:没有升级的 IBM 随用随付帐户。
值得记住这一点,因为其他用户可能 运行 遇到相同的错误消息,但不知道该怎么做。