5

When I use webkit2png on my SSH-server, I get the error: "Cannot connect to X server:0.0" Webkit2png is a package that makes a PNG screenshots of htmlpages. On my computer it worked perfectly, but on the SSH server not; it doens't create an PNG-image.

It only works when I do this command:

xvfb-run -a -s "-screen 0 640x480x16" python webkit2pngProgram.py

But that's an Unix command, and not Python code.

The webkit2pngProgram code:

from webkit2png import WebkitRenderer, init_qtgui
from PyQt4.QtCore import QTimer

def renderer_func():
   renderer = WebkitRenderer()
   renderer.width = 550
   renderer.height = 500   
   renderer.timeout = 10
   renderer.wait = 1
   renderer.format = "png"
   renderer.grabWholeWindow = False
   y = Program()
   outfile = open("/image.png", "w")

   renderer.render_to_file("/test.html", file=outfile)
   outfile.close()

def start():
   app = init_qtgui()   ###### => STUCKS HERE
   QTimer.singleShot(0, renderer_func)
   app.exec_()

if __name__ == "__main__":
    start()

Thanks for your help!

Francis Michels
  • 117
  • 1
  • 3
  • 7
  • At least link to the `webkit2png` source, website, docs, and tell us if you looked at the docs for how to set the xserver and what they said? – agf Aug 03 '11 at 13:32

1 Answers1

2

You need to run the xvfb unix command first (X Virtual Frame Buffer)

server_num = int(os.getpid() + 1e6) 
newArgs = ["xvfb-run", "--auto-servernum", "--server-num", str(server_num), "--server-args=-screen 0, %dx%dx24" % (1024, 768), sys.argv[0], '-g','1024', '768'] 
os.execvp(newArgs[0],newArgs[1:]) 
Jonathan
  • 6,741
  • 7
  • 52
  • 69