当我在我的SSH服务器上使用webkit2png时,我收到错误:"无法连接到X服务器:0.0"Webkit2png是一个包含htmlpages的PNG屏幕截图的软件包.在我的电脑上,它工作得很好,但在SSH服务器上没有; 它不会创建一个PNG图像.
它只在我执行此命令时有效:
xvfb-run -a -s "-screen 0 640x480x16" python webkit2pngProgram.py
Run Code Online (Sandbox Code Playgroud)
但这是一个Unix命令,而不是Python代码.
webkit2pngProgram代码:
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()
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我尝试从python发送邮件到多个电子邮件地址,从.txt文件导入,我尝试了不同的语法,但没有什么可行的...
代码:
s.sendmail('sender@mail.com', ['recipient@mail.com', 'recipient2@mail.com', 'recipient3@mail.com'], msg.as_string())
Run Code Online (Sandbox Code Playgroud)
所以我尝试从.txt文件导入收件人地址:
urlFile = open("mailList.txt", "r+")
mailList = urlFile.read()
s.sendmail('sender@mail.com', mailList, msg.as_string())
Run Code Online (Sandbox Code Playgroud)
mainList.txt包含:
['recipient@mail.com', 'recipient2@mail.com', 'recipient3@mail.com']
Run Code Online (Sandbox Code Playgroud)
但它不起作用......
我也尝试过这样做:
... [mailList] ... in the code, and '...','...','...' in the .txt file, but also no effect
Run Code Online (Sandbox Code Playgroud)
和
... [mailList] ... in the code, and ...','...','... in the .txt file, but also no effect...
Run Code Online (Sandbox Code Playgroud)
有谁知道该怎么办?
非常感谢!
我正在尝试在类中设置我的Python程序.但是当我有这个:
class program:
def test(value):
print value + 1
def functionTest():
a = test(2)
if __name__ == "__main__":
functionTest()
Run Code Online (Sandbox Code Playgroud)
我收到错误:NameError:未定义全局名称'test'
我需要做些什么来"激活"测试方法?非常感谢!