manage.py:无法连接到X服务器 [英] manage.py: cannot connect to X server

查看:91
本文介绍了manage.py:无法连接到X服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 PyQt4.QtWebkit 来对Django应用程序中的网页进行爬网。在生产环境中,该模块无法对其进行爬网。它会引发错误 manage.py:无法连接到X服务器

I have used PyQt4.QtWebkit to crawl the web page in my django application.In the production environment that module doesn't work to crawl it.it throws the error "manage.py: cannot connect to X server"

我的Qt类:

class Render(QWebPage):
 def __init__(self, url):
    self.app = QApplication(sys.argv)
    QWebPage.__init__(self)
    self.loadFinished.connect(self._loadFinished)
    self.mainFrame().load(QUrl(url))
    self.app.exec_()

 def _loadFinished(self, result):
    self.frame = self.mainFrame()
    self.app.quit() 

从Django外壳调用:

calling from django-shell:

 r = Render(url)

当我使用Django-shell(python manage.py shell)通过django调用此 Render类时,render函数将引发错误。
您能帮我吗?

when i call this "Render" class through django with the Django-shell(python manage.py shell) the render function throws the error. could you please help me on this?

推荐答案

原因是 Xvfb

我需要使用xvfb在bash shell中运行我的python程序( X虚拟帧缓冲区)
同样,

i need to run my python program in bash shell with xvfb(X virtual frame buffer) likewise,

ubuntu@localhost$ xvfb-run python webpage_scrapper.py http://www.google.ca/search?q=navaspot

它给出结果。

现在我的要求是我需要在python中执行此shell命令并等待tine收集结果。我必须处理结果。

Now My requirement is i need to execute this shell command in python and waiting for tine to collect the result.I have to process the result.

您能否建议我在python上有效执行此命令。

Could you please suggest me for executing this command on python effectively.

这篇关于manage.py:无法连接到X服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆