manage.py: cannot connect to X server

Nava picture Nava · Dec 21, 2011 · Viewed 7.3k times · Source

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"

My Qt class :

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() 

calling from django-shell:

 r = Render(url)

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?

Answer

Nava picture Nava · Dec 22, 2011

The Reason is "Xvfb"

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

It gives the result.

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.

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