views:

153

answers:

2

I want to hit a URL from python in google app engine. Can any one please tell me how can i hit the URL using python in google app engine.

+5  A: 

You can use the URLFetch API

from google.appengine.api import urlfetch

url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
  doSomethingWithResult(result.content)
AutomatedTester
I want to fetch this URL via GAE cron job. But I am getting failure.Can you please tell me How can I fetch this URL via cron job? As I cannot test this this from my local machine.
We need more details than just "failure".
Nick Johnson
can you give us the error that is returned
AutomatedTester
A: 

It always depends on post or get. urllib can post to a form somewhere else, if we want the rather tricky thing validate between different hashes (sha and md5)

import urllib             
data = urllib.urlencode({"id" : str(d), "password" : self.request.POST['passwd'], "edit" : "edit"})
result = urlfetch.fetch(url="http://www..../Login.do",
payload=data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
if result.content.find('loggedInOrYourInfo') > 0:                    
  self.response.out.write("clear")                          
else:                
  self.response.out.write("wrong password ")
LarsOn