Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle App Engine - Error uploading file to blobstore from Python code
    primarykey
    data
    text
    <p>I am working on an app to process emails hitting my mailbox. I have modified my mail settings to forward incoming mails to <strong>myapp</strong>. The mails reaching <strong>myapp</strong> will be routed to the handler script ("<strong>handle_incoming_email.py</strong>") where it will be processed. My <strong>app.yaml</strong> file looks like this</p> <p>app.yaml</p> <pre><code>application: myapp version: 1-1 runtime: python27 api_version: 1 threadsafe: false default_expiration: "360d" handlers: - url: /_ah/mail/.+ script: myapp/utils/handle_incoming_email.py </code></pre> <p>The mail handler script is given below</p> <p>handle_incoming_email.py</p> <pre><code>import logging import urllib import base64 import traceback from google.appengine.ext import webapp from google.appengine.ext import blobstore from google.appengine.api import urlfetch from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext.webapp.mail_handlers import InboundMailHandler class ReceiveEmail(InboundMailHandler): def receive(self, message): try: for filename, filecontents in message.attachments: if filecontents.encoding: # data = filecontents data = filecontents.decode() # data = filecontents.payload # data = filecontents.payload.decode() # data = base64.b64decode(filecontents.decode()) # data = base64.b64decode(filecontents.payload) # data = base64.b64decode(filecontents.payload.decode()) upload_url = blobstore.create_upload_url('http://myapp.appspot.com/settings/saveItem/') form_fields = {'field_name': data} form_data = urllib.urlencode(form_fields) result = urlfetch.fetch(url=upload_url, payload=form_data, method=urlfetch.POST, headers={'Content-Type': 'application/x-www-form-urlencoded'}) logging.info(result) except Exception, e: traceback.print_exc() application = webapp.WSGIApplication([ReceiveEmail.mapping()], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main() </code></pre> <p>My requirement is to create an entity corresponding to each mail with attachment. For this, I need to parse the attachment from the mail and upload it to blobstore. However, when I try to upload the attachment to blobstore, I get the following error:</p> <p><em>The request's content type is not accepted on this URL.</em></p> <p>As you can see in the commented code in "handle_incoming_email.py", I tried different methods (trial-and-error) to get the data correct, but to no avail.</p> <p>Could someone guide me in fixing this!</p> <p>Thanks!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload