doutui8842 2013-06-17 22:21
浏览 238
已采纳

GAE Go用户服务登录网址包含%A(MISSING)

So this one's been puzzling me for a little while!

Here's some code in the console:

 func GetLoginLinks(w *http.ResponseWriter, r *http.Request) (string, error) {
    c := appengine.NewContext(r)
    u := user.Current(c)
    if u == nil {
        url, err := user.LoginURL(c, r.URL.String())
        if err != nil {
            http.Error(*w, err.Error(), http.StatusInternalServerError)
            return "", err
        }

        c.Debugf("Return url: " + r.URL.String())
        c.Debugf("login url: " + url)
        c.Debugf("url type: %T", url)
        v := LoginItem(url, "Login")
        return v, nil
    }
 }

It gives the following output:

2013/06/17 21:48:28 DEBUG: Return url: /
2013/06/17 21:48:28 DEBUG: login url: /_ah/login?continue=http%A(MISSING)//localhost%A(MISSING)8080/
2013/06/17 21:48:28 DEBUG: url type: string

This also fails when uploaded to the app engine itself.

What I'm struggling with is the first 4 lines of the function comes directly from the developer guide.

  • 写回答

1条回答 默认 最新

  • dongliechuich10319 2013-06-18 06:00
    关注

    package fmt

    Format errors:

    If an invalid argument is given for a verb, such as providing a string to %d, the generated string will contain a description of the problem, as in these examples:

    Wrong type or unknown verb: %!verb(type=value)
      Printf("%d", hi):          %!d(string=hi)
    Too many arguments: %!(EXTRA type=value)
      Printf("hi", "guys"):      hi%!(EXTRA string=guys)
    Too few arguments: %!verb(MISSING)
      Printf("hi%d"):            hi %!d(MISSING)
    Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC)
      Printf("%*s", 4.5, "hi"):  %!(BADWIDTH)hi
      Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi
    

    All errors begin with the string "%!" followed sometimes by a single character (the verb) and end with a parenthesized description.

    If an Error or String method triggers a panic when called by a print routine, the fmt package reformats the error message from the panic, decorating it with an indication that it came through the fmt package. For example, if a String method calls panic("bad"), the resulting formatted message will look like

    %s(PANIC=bad)
    

    The %s just shows the print verb in use when the failure occurred.

    You have an invalid format string. You have an escaped URL query string in a format string: ":" is escaped to "%3A". The format arguments for the "%3A" verbs are missing. For safety, never use an arbitrary string as a format string. For example,

    package main
    
    import "fmt"
    
    func main() {
        url := "/_ah/login?continue=http%3A//localhost%3A8080/"
        fmt.Printf("login url: " + url)
        fmt.Println()
        fmt.Printf("login url: %s", url)
        fmt.Println()
    }
    

    Output:

    login url: /_ah/login?continue=http%A(MISSING)//localhost%A(MISSING)8080/
    login url: /_ah/login?continue=http%3A//localhost%3A8080/
    

    Write:

    c.Debugf("login url: %s", url)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog