http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://developers.google.com/appengine/docs/go/urlfetch/overview
This error message was received while testing PayPal OAuth on GAE dev_appserver.py (works when creating at compilation)
const url string = "https://api.sandbox.paypal.com/v1/oauth2/token" const username string = "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp" const password string = "EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" client := &http.Client{} req, _ := http.NewRequest("POST", url, strings.NewReader("grant_type=client_credentials")) req.SetBasicAuth(username, password) req.Header.Set("Accept", "application/json") req.Header.Set("Accept-Language", "en_US") req.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp, err := client.Do(req)
As you can see, the Go App Engine breaks http.DefaultTransport (GAE_SDK / goroot / src / pkg / appengine_internal / internal.go, line 142, GAE 1.7.5)
type failingTransport struct{} func (failingTransport) RoundTrip(*http.Request) (*http.Response, error) { return nil, errors.New("http.DefaultTransport and http.DefaultClient are not available in App Engine. " + "See https://developers.google.com/appengine/docs/go/urlfetch/overview") } func init() {
It helped me with Go App Engine 1.7.5
transport := http.Transport{} client := &http.Client{ Transport: &transport, } req, _ := http.NewRequest("POST", url, strings.NewReader("grant_type=client_credentials")) req.SetBasicAuth(username, password) req.Header.Set("Accept", "application/json") req.Header.Set("Accept-Language", "en_US") req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
source share