Hi, Jeremy,
Thank you so much for such a quick response!
Now my code runs well on GAE. I'd like to share some portion of it for
anyone else in need.
# make sure s is no more than 4,000 characters long before
urlencoded
def translate(self, s, lang):
params = {'q': s, 'v': '1.0', 'langpair': '|%s' % lang,
'format': 'html'}
# payload can be as long as 5,000 characters after urlencoded
response = urlfetch.fetch(url = _GOOGLE_TRANSLATE_BASE,
payload = urllib.urlencode(params),
method = urlfetch.POST,
headers = {'Content-Type': 'application/x-www-form-
urlencoded'})
data = simplejson.loads(response.content)
if data['responseStatus'] == 200:
return data['responseData']['translatedText']
else:
return '<h1>' + _ERROR_TITLE + '</h1><p class="e">' + str
(data['responseStatus']) + '</p>'
On Nov 30, 11:55 pm, Jeremy Geerdes <
jrgeer...@gmail.com> wrote:
> To answer your questions as you asked them:
>
> 1) Yes, the RESTful interface supports POST requests. Via POST, you
> can submit source strings as long as 5,000 characters.
>
> 2) To fix the malformed request, make sure that your q string and
> langpair are urlencoded, even if you're using POST. Especially check
> to check that the vertical pipe ( | ) in the langpair. And regarding
> the url that's too long, make sure that your url, with all parameters
> correctly encoded, is coming in less than 2,000 characters. This
> shouldn't be a problem if you use POST, as long as you stay within the
> 5K character limit.
>
> Jeremy R. Geerdes
> Effective website design & development
> Des Moines, IA
>
> For more information or a project quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://
jgeerdes.wordpress.com
>
jgeer...@mchsi.com
>
> Unless otherwise noted, any price quotes contained within this
> communication are given in US dollars.
>
> If you're in the Des Moines, IA, area, check out Debra Heights
> Wesleyan Church!
>
> And check out my blog, Adventures in Web Development, athttp://
jgeerdes.blogspot.com