sending POST data via urlfetch

204 views
Skip to first unread message

wachaca

unread,
Apr 8, 2008, 4:18:50 PM4/8/08
to Google App Engine
Hello,
I have a certain code working in PHP, which I am migrating to Python
in order to get it work under my App.

This is the original code in PHP which works, at the end I get a nice
long XML feed.

$post_data = array();

$post_data['accountType'] = "HOSTED_OR_GOOGLE";
$post_data['Email'] = "m...@email.com";
$post_data['Passwd'] = "mypass";
$post_data['service'] = "cp";
$post_data['source'] = "Beta-Api";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/
ClientLogin" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_HEADER, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
print $postResult;
curl_close($ch);


In Python, this would translate to:
url = "https://www.google.com/accounts/ClientLogin"
payload = "accountType=HOSTED_OR_GOOGLE&service=cp&source=Beta-
Api&Email=my%40email.com&Passwd=mypass"
result = urlfetch.fetch(url,payload,2)

However, in the Python script, I always get
result.status_code = 403
Error=BadAuthentication

Am I making a mistake in thebuilding the payload parameter?

Thanks for your help

ma...@google.com

unread,
Apr 8, 2008, 6:25:24 PM4/8/08
to Google App Engine
Hi,
It looks like you may be trying to fetch a Gdata feed with Google App
Engine. Our Gdata team has updated the Python client library to
include Google App Engine support, so you may consider using the
library, you can find information about the release here:
http://googledataapis.blogspot.com/2008/04/release-hounds-support-for-app-engine.html

-Marzia

EuGeNe

unread,
Apr 9, 2008, 5:43:37 AM4/9/08
to Google App Engine

wachaca

unread,
Apr 9, 2008, 5:56:15 PM4/9/08
to Google App Engine
How did you figure out that payload was dictionary?
There is nothing about that in the manual at
http://code.google.com/appengine/docs/urlfetch/fetchfunction.html

Anyways, I tried the following code and it did not work.

url = "https://www.google.com/accounts/ClientLogin"

data = urlencode({'accountType':'HOSTED_OR_GOOGLE', 'service':'cp',
'source':'Tigabytes-Contacts-Api', 'Email':self.request.get("email"),
'Passwd':self.request.get("pass")})

result = urlfetch.fetch(url,payload=data,method=urlfetch.POST)

Guess I'll have to download the client library.
> http://groups.google.com/group/google-appengine/browse_thread/thread/...
Reply all
Reply to author
Forward
0 new messages