解析JSON时间错误

I am trying to parse a timestamp that is generated in python and posted over to here to be stored in cassandra and I am getting a weird error.

parsing time ""2015-11-05 14:14:32-0700"" as ""2006-01-02T15:04:05Z07:00"": cannot parse " 14:14:32-0700"" as "T"

I don't want to modify the time given to me from the python in anyway, just want to pass it right into cassandra but the driver says I need to have it be time.Time (not string) to do so.

Here is the code

type OurCustomType struct {
    TimeStamp   time.Time `json:"timestamp"`
}


func extractJsonBody(r *http.Request) []byte {
    body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
    if err != nil {
        //...
    }
    if err := r.Body.Close(); err != nil {
         //....
    }
    return body
}

func View(w http.ResponseWriter, r *http.Request) {
    var variable OurCustomType

    body := extractJsonBody(r)

    if err := json.Unmarshal(body, &variable); err != nil {
        //..
    } else {
        //...
    }
}

Edit: I have implemented my own time.Time type and implemented a custom UnmarshalJSON to attempt to fix this issue.

type PythonTime struct {
    time.Time
}

func (self *PythonTime) UnmarshalJSON(b []byte) (err error) {
    self.Time, err = time.Parse("2006-01-02 15:04:05-0700", string(b))
    return
}

But I am not getting this error:

parsing time ""2015-11-05 14:14:32-0700"" as "2006-01-02 15:04:05-0700": cannot parse ""2015-11-05 14:14:32-0700"" as "2006"

The problem here is that you've got quotations in the date being passed from Python.

In the first error that you posted, you can see that it failed at reading "T". That's because you were using a different format in Go than you were returning from Python.

parsing time ""2015-11-05 14:14:32-0700"" as ""2006-01-02T15:04:05Z07:00"": cannot parse " 14:14:32-0700"" as "T"

You used ""2006-01-02T15:04:05Z07:00"" when the format from Python is ""2006-01-02 15:04:05-0700"".

The same is true in your last error, except that you dropped the one pair of the quotations in the date format verses what you have returned in Python.

parsing time ""2015-11-05 14:14:32-0700"" as "2006-01-02 15:04:05-0700": cannot parse ""2015-11-05 14:14:32-0700"" as "2006"

This is saying that you provided "2006-01-02 15:04:05-0700" but it's expecting ""2006-01-02 15:04:05-0700"" due to the extra quotes in the date returned by Python.