Python 在webapp2-googleappengine中读取表单文件

Python 在webapp2-googleappengine中读取表单文件,python,google-app-engine,python-2.7,beautifulsoup,webapp2,Python,Google App Engine,Python 2.7,Beautifulsoup,Webapp2,我正在使用multipart/form/data上传一个xml文件,需要读取xml文件内容并在response.write()中打印xml文件内容 电话 class MPost(webapp2.RequestHandler): def post(self): uploaded_file = self.request.body self.response.headers['Content-Type'] = 'text/plain' self.respon

我正在使用multipart/form/data上传一个xml文件,需要读取xml文件内容并在response.write()中打印xml文件内容

电话

  class MPost(webapp2.RequestHandler):
    def post(self):
     uploaded_file  = self.request.body
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.write(str(uploaded_file))
似乎正在生成unicode字符串,而不是文件对象。在下一行中,您将调用read()方法,就像它是一个文件对象一样。因此

AttributeError:“unicode”对象没有属性“read”


下面是将xml文件作为字符串写入web的示例代码


使用请求正文和body_文件代替请求参数:body是作为字节字符串的正文内容,body_文件为相同的数据提供了一个类似文件的接口:

你能把问题弄清楚吗,你到底想做什么。也许再详细一点。你为什么给这个问题加上标签?而且,它可能是webapp2而不是webapp1。马虎的现在的孩子们……呃,在书名里?哦,你在评论后更正了。好的,试着在这个节目上提供帮助
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\uniphoreC08\Desktop\upload_grammar\helloworld.py", line 35, in post
    f.read()
AttributeError: 'unicode' object has no attribute 'read'  
self.request.get('filecoll')
  class MPost(webapp2.RequestHandler):
    def post(self):
     uploaded_file  = self.request.body
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.write(str(uploaded_file))