Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 使用lxml导入谷歌应用程序引擎_Google App Engine_Lxml_Elementtree - Fatal编程技术网

Google app engine 使用lxml导入谷歌应用程序引擎

Google app engine 使用lxml导入谷歌应用程序引擎,google-app-engine,lxml,elementtree,Google App Engine,Lxml,Elementtree,我使用lxml解析页面。当我使用app engine sdk运行我的代码时,它可以工作,但当我在云中部署我的应用程序时,我在这里得到一个消息: 回溯(最近一次呼叫最后一次): 文件“/base/data/home/apps/s~testparsercyka/1.356245976008257055/handler_info.py”,第2行,在 导入lxml.html 文件“/base/data/home/apps/s~testparsercyka/1.356245976008257055/lxm

我使用lxml解析页面。当我使用app engine sdk运行我的代码时,它可以工作,但当我在云中部署我的应用程序时,我在这里得到一个消息:

回溯(最近一次呼叫最后一次): 文件“/base/data/home/apps/s~testparsercyka/1.356245976008257055/handler_info.py”,第2行,在 导入lxml.html 文件“/base/data/home/apps/s~testparsercyka/1.356245976008257055/lxml/html/init.py”,第12行,在 从lxml导入etree ImportError:无法导入名称etree

代码:

app.yaml

handler_info.py


导入lxml
导入lxml.html
导入URL库
从google.appengine.ext导入webapp
从google.appengine.ext.webapp.util导入运行\u wsgi\u应用程序
从google.appengine.ext.webapp导入模板
导入操作系统
导入cgi
类主页(webapp.RequestHandler):
def get(自我):
模板_值={}
path=os.path.join(os.path.dirname(_文件__),'index.html')
self.response.out.write(template.render(路径、模板值))
类处理程序(webapp.RequestHandler):
def post(自我):
#url=”http://habrahabr.ru/"
url=str(self.request.get('url'))
url\u temp=url
teg=str(self.request.get('teg'))
attr=str(self.request.get('attr'))
n0=str(self.request.get('n0'))
n=str(self.request.get('n'))
a=属性拆分(“:”)
对于范围内的i(int(n0),int(n)):
url=url.format(str(i))
self.response.out.write(url)
html=urllib.urlopen(url.read())
doc=lxml.html.document\u fromstring(html)
url=url\u temp
self.getn(doc.getroottree().getroot(),teg,a)
def getn(自身、节点、teg、a):
如果((node.tag==teg)和(node.get(a[0])==a[1]):
#打印node.tag,node.keys()
self.response.out.write(node.text)
self.response.out.write(“
”) 对于节点中的n: self.getn(n,teg,a) application=webapp.WSGIApplication([('/',主页),('/sign',Handlers)],debug=True) def main(): 运行应用程序(应用程序) 如果名称=“\uuuuu main\uuuuuuuu”: main()

你知道为什么这不起作用吗?

我知道这是一个老问题,但下面是一个我已确认在部署到App Engine时起作用的答案:

应用程序yaml

application: lxml-test
version: 1
runtime: python27
api_version: 1
threadsafe: false

handlers:
- url: /.*
  script: app.app

libraries:
- name: lxml
  version: "2.3"

- name: webapp2
  version: "latest"
app.py

import webapp2
import lxml.etree

class MainPage(webapp2.RequestHandler):
    def get(self):
        root = lxml.etree.XML('<top><content>Hello world!</content></top>')
        self.response.content_type = 'text/xml'
        self.response.write(lxml.etree.tostring(root, xml_declaration=True))

app = webapp2.WSGIApplication(routes=[('/', MainPage)], debug=True)
导入webapp2
导入lxml.etree
类主页(webapp2.RequestHandler):
def get(自我):
root=lxml.etree.XML('Hello world!')
self.response.content_type='text/xml'
self.response.write(lxml.etree.tostring(root,xml_声明=True))
app=webapp2.WSGIApplication(routes=[('/',MainPage)],debug=True)
因此,在将上述内容与代码进行比较时,以下一些更改可能会有所帮助:

  • script:hander\u info.py
    更改为
    script:handler\u info.application
  • 使用webapp2,它比
    webapp
    更好更新

  • 也有可能是这个问题自2012年被问到后就自行解决了。

    嗨,阿泰姆,我也遇到了类似的问题,除了我在SDK中遇到导入错误,所以我还没有在谷歌的服务器上尝试过。您必须自己在计算机上安装lxml吗?我不知道这是否是我的问题,但我认为它会随SDK一起出现。。。
    application: lxml-test
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: false
    
    handlers:
    - url: /.*
      script: app.app
    
    libraries:
    - name: lxml
      version: "2.3"
    
    - name: webapp2
      version: "latest"
    
    import webapp2
    import lxml.etree
    
    class MainPage(webapp2.RequestHandler):
        def get(self):
            root = lxml.etree.XML('<top><content>Hello world!</content></top>')
            self.response.content_type = 'text/xml'
            self.response.write(lxml.etree.tostring(root, xml_declaration=True))
    
    app = webapp2.WSGIApplication(routes=[('/', MainPage)], debug=True)