Hello altogether,
I figured out how to use the urlfetch.fetch() method.
The following code would work:
============================== CODE ==============================
resultXmlStr = urlfetch.fetch(url=self.MECHANICAL_TURK_URL,
payload=urllib.urlencode
(self.parameters),
method=urlfetch.POST,
headers={'Content-Type':
'application/x-www-form-urlencoded'}))
resultXML = xml.dom.minidom.parseString(resultXmlStr.content)
==================================================================
Still, the error "DownloadError: ApplicationError: 2" related to
urlfetch.py remains quite the same.
>From what I learnt from this forum this is quite a common error in
GAE. Does anyone has any idea on how get this to work? I would be very
happy if someone would have an idea in where to take a closer look in
order to make it work online.
Friendly,
Benjamin
On 5 Jun., 13:59, zellerfossil <[email protected]> wrote:
> Dear Google App Engine Group,
>
> since a couple of days I am developing an application within GAE to
> communicate with Amazon's Mechanical Turk REST API. Everything is
> working perfectly when I am testing locally in my development
> environment. After I upload my application to GAE I keep geeting
> Errors obviously related to urllib ore urlfetch.
>
> ============================== ERROR ==============================
> The error I am constantly receiving is the following:
>
> Traceback (most recent call last):
> File "/base/python_lib/versions/1/google/appengine/ext/webapp/
> __init__.py", line 501, in __call__
> handler.get(*groups)
> File "/base/python_lib/versions/1/google/appengine/ext/webapp/
> util.py", line 57, in check_login
> handler_method(self, *args)
> File "/base/data/home/apps/guerval/1.333984421936062328/guerval.py",
> line 154, in get
> mtcGetHitConnector.sendRequest()
> File "/base/data/home/apps/guerval/1.333984421936062328/
> MTCConnectors/GenericMechanicalTurkConnector.py", line 68, in
> sendRequest
> urllib.urlencode(self.parameters)).read()
> File "/base/python_dist/lib/python2.5/urllib.py", line 84, in
> urlopen
> return opener.open(url, data)
> File "/base/python_dist/lib/python2.5/urllib.py", line 192, in open
> return getattr(self, name)(url, data)
> File "/base/python_dist/lib/python2.5/urllib.py", line 328, in
> open_http
> errcode, errmsg, headers = h.getreply()
> File "/base/python_dist/lib/python2.5/httplib.py", line 306, in
> getreply
> response = self._conn.getresponse()
> File "/base/python_dist/lib/python2.5/httplib.py", line 194, in
> getresponse
> self._allow_truncated, self._follow_redirects)
> File "/base/python_lib/versions/1/google/appengine/api/urlfetch.py",
> line 240, in fetch
> return rpc.get_result(allow_truncated)
> File "/base/python_lib/versions/1/google/appengine/api/urlfetch.py",
> line 387, in get_result
> self.check_success(allow_truncated)
> File "/base/python_lib/versions/1/google/appengine/api/urlfetch.py",
> line 355, in check_success
> raise DownloadError(str(e))
> DownloadError: ApplicationError: 2
> ==================================================================
>
> The code that is causing this error looks as follows: (The initiating
> code is marked with #####-rows above and below.)
> ============================== CODE ==============================
> '''
> Created on 21.05.2009
>
> @author: benjamin.zeller
> '''
>
> # Import libraries
> import time
> import hmac
> import sha
> import base64
> import urllib
> import xml.dom.minidom
> from google.appengine.api import urlfetch
>
> class GenericMechanicalTurkConnector():
> AWS_ACCESS_KEY_ID = ""
> AWS_SECRET_ACCESS_KEY = ""
> SERVICE_NAME = ""
> SERVICE_VERSION = ""
> MECHANICAL_TURK_URL = ""
>
> operation = ""
> timestamp = ""
> signature = ""
>
> parameters = ""
>
> resultXML = ""
>
> def __init__(self, operation):
> self.AWS_ACCESS_KEY_ID = "<AWS_ACCESS_KEY_ID>"
> self.AWS_SECRET_ACCESS_KEY = "<AWS_SECRET_ACCESS_KEY>"
> self.SERVICE_NAME = "AWSMechanicalTurkRequester"
> self.SERVICE_VERSION = "2008-04-01"
> ''' Production Environment '''
> '''self.MECHANICAL_TURK_URL = "http://
> mechanicalturk.amazonaws.com/onca/xml?"'''
> ''' Development Environment '''
> self.MECHANICAL_TURK_URL = "http://
> mechanicalturk.sandbox.amazonaws.com?"
>
> self.operation = operation
> self.timestamp= self.generateTimestamp(time.gmtime())
> self.signature = self.generateSignature(self.SERVICE_NAME,
> self.operation, self.timestamp, self.AWS_SECRET_ACCESS_KEY)
>
> self.parameters = {
> 'Service': self.SERVICE_NAME,
> 'Version': self.SERVICE_VERSION,
> 'AWSAccessKeyId':
> self.AWS_ACCESS_KEY_ID,
> 'Timestamp': self.timestamp,
> 'Signature': self.signature,
> 'Operation': self.operation,
> }
>
> self.resultXML = "";
>
> # Define authentication routines
> def generateTimestamp(self, gmtime):
> return time.strftime("%Y-%m-%dT%H:%M:%SZ", gmtime)
>
> def generateSignature(self, service, operation, timestamp,
> secret_access_key):
> my_sha_hmac = hmac.new(secret_access_key, service + operation
> + timestamp, sha)
> my_b64_hmac_digest = base64.encodestring(my_sha_hmac.digest
> ()).strip()
> return my_b64_hmac_digest
>
> # Make the request
> def sendRequest(self):
> ################################## ERROR CAUSE
> ##################################
> resultXmlStr = urllib.urlopen(self.MECHANICAL_TURK_URL,
> urllib.urlencode
> (self.parameters)).read()
> ###################################################################################
> #resultXmlStr = urlfetch.fetch(url=self.MECHANICAL_TURK_URL,
> # payload=urllib.urlencode
> (self.parameters),
> # method=urlfetch.POST,
> # )
> print "Debug output: " + resultXmlStr
>
> resultXML = xml.dom.minidom.parseString(resultXmlStr)
> self.resultXML = resultXML
>
> def checkForErrorMessage(self, xml):
> errorMessage = ""
> # Check for and print results and errors
> errors_nodes = xml.getElementsByTagName('Errors')
> if errors_nodes:
> print 'There was an error processing your request:'
> for errors_node in errors_nodes:
> for error_node in errors_node.getElementsByTagName
> ('Error'):
> errorMessage = ' Error code: ' +
> error_node.getElementsByTagName('Code')[0].childNodes[0].data
> errorMessage += ' Error message: ' +
> error_node.getElementsByTagName('Message')[0].childNodes[0].data
> if errorMessage != "":
> return errorMessage
>
> def getResult(self):
> raise NotImplementedError
> ==================================================================
>
> Does anyone has any suggestions on how I could resolve this error. I
> was already trying the urlfetch.fetch() method (as you can see in the
> code) but then the line xml.dom.minidom.parseString(resultXmlStr) did
> not work anymore.
>
> I am thankfull for any hints or suggestions
>
> Friendly,
> Benjamin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---