Im trying to request https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=%5Bhttp://www.my-website.dk/%5D&key=%5Bmy-key%5D using urlfetch from app engine but it’s not working.
When I access it and hardcode my-url into the request like this: https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://www.my-website.dk/&key=%5Bmy-key%5D it’s working fine, but when I use urlfetch.fetch(“https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=%s&key=%5Bmy-key%5D”, “http://www.my-website.dk”) it’s not working, I have also tried:
page_content = urlfetch.fetch(
url="https://www.googleapis.com/pagespeedonline/v1/runPagespeed",
payload=params,
method=urlfetch.GET
)
and then serving the parameters in the payload like this:
params = urllib.urlencode({
"url": page.link,
"key": "[my-key]"
})
but the result is the same, it’s not working and the service gives me HTTP status code 400. I also tried adding urlfetch.fetch(u(“http://…”, page.link) but the result is the same.
I edited the code based on the reply from systempuntoout incase any one should run into the same problem:
params = urllib.urlencode({
"url": page.link,
"key": "AIzaSyAFpm6W_OmjQl33JC98mAPkvrdGmrR0i4Y"
})
page_content = urlfetch.fetch("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?%s" % params)
First, the
urlfetchcall has an error because you are passing two parameters to the function.You should use the
%between the two strings to pass just one url parameter to the function.Then, have you tried to urlencode the second url?