在远程Windows系统上重新启动服务的最简单的编程方法是什么?语言或方法无关紧要,只要它不需要人为干预即可.
我需要扫描IP列表并从该IP上的证书中检索公用名(对于允许端口443连接的每个IP).我已经能够使用套接字和ssl模块成功完成此操作.它适用于所有具有有效签名证书的IP,但不适用于自签名证书.
如果我使用此方法,则需要由我的CA-bundle验证的有效证书:
from socket import socket
import ssl
s = socket()
c = ssl.wrap_socket(s,cert_reqs=ssl.CERT_REQUIRED, ca_certs='ca-bundle.crt')
c.connect(('127.0.0.1', 443))
print c.getpeercert()
Run Code Online (Sandbox Code Playgroud)
如果我删除它cert_reqs=ssl.CERT_REQUIRED然后连接但根本没有获得证书.
如何验证IP上的证书的通用名称,无论它是否针对ca-bundle进行验证?
在我的应用程序中,我在包中使用模块example调用examplemod.
我的应用:
from example import examplemod
examplemod.do_stuff()
Run Code Online (Sandbox Code Playgroud)
它会example像这样导入另一个模块.
examplemod.py:
from example import config
# uses config
# then does stuff
Run Code Online (Sandbox Code Playgroud)
config 使用常数.
config.py:
CONSTANT = "Unfortunate value"
Run Code Online (Sandbox Code Playgroud)
当我examplemod在我的应用程序中使用它时CONSTANT = "Better value",我想覆盖这个常量(设置它),我不想修改底层模块,所以我不必维护自己的包.我怎样才能做到这一点?
我想访问用户的Google Plus One历史记录
启用+1后,历史记录会保存在您的Google个人资料中,并可选择显示:
http://www.google.com/+1/button/
可以通过编程方式访问(一旦用户通过正常的Google身份验证和授权授予权限?)
我只能找到API的信息,以便将按钮添加到网站.
我正在使用带有-y和--suppress-common-lines选项的差异,输出几乎是完美的,除了我想看到更改的行号.
例:
文件1:
line a
line b
line c
Run Code Online (Sandbox Code Playgroud)
文件2:
line a
line B
line c
line d
Run Code Online (Sandbox Code Playgroud)
命令和输出:
$ diff -y --suppress-common-lines file1 file2
line b | line B
> line d
Run Code Online (Sandbox Code Playgroud)
这种选项的组合是否可以与diff结合使用,还是需要其他工具?
我有一个Scrapy CrawlSpider,它有一个非常大的要抓取的URL列表.我希望能够阻止它,保存当前状态并在以后恢复它而不必重新开始.有没有办法在Scrapy框架内实现这一目标?
我知道我从Unicode转换有问题,但我不确定它在哪里发生.
我正在从HTML文件目录中提取有关最近Eruopean旅行的数据.某些位置名称具有非ASCII字符(例如é,ô,ü).我正在使用正则表达式从文件的字符串表示中获取数据.
如果我在找到它们时打印位置,它们会打印出字符,因此编码必须正常:
Le Pré-Saint-Gervais, France
Hôtel-de-Ville, France
Run Code Online (Sandbox Code Playgroud)
我使用SQLAlchemy将数据存储在SQLite表中:
Base = declarative_base()
class Point(Base):
__tablename__ = 'points'
id = Column(Integer, primary_key=True)
pdate = Column(Date)
ptime = Column(Time)
location = Column(Unicode(32))
weather = Column(String(16))
high = Column(Float)
low = Column(Float)
lat = Column(String(16))
lon = Column(String(16))
image = Column(String(64))
caption = Column(String(64))
def __init__(self, filename, pdate, ptime, location, weather, high, low, lat, lon, image, caption):
self.filename = filename
self.pdate = pdate
self.ptime = ptime
self.location = location
self.weather = weather
self.high …Run Code Online (Sandbox Code Playgroud) 我希望能够允许用户在生成长期运行的GCI脚本时查看输出,而不是在脚本完成后查看.但是,即使我明确刷新STDOUT,服务器似乎也等待脚本完成,然后再将响应发送到客户端.这是在运行Apache 2.2.9的Linux服务器上.
示例python CGI:
#!/usr/bin/python
import time
import sys
print "Content-type: text/plain"
print
for i in range(1, 10):
print i
sys.stdout.flush()
time.sleep(1)
print "Done."
Run Code Online (Sandbox Code Playgroud)
perl中的类似示例:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
for ($i = 1; $i <= 10 ; $i++) {
print "$i\n";
sleep(1);
}
print "Done.";
Run Code Online (Sandbox Code Playgroud)
此链接表示从Apache 1.3 CGI输出应该是无缓冲的(但这可能仅适用于Apache 1.x):http://httpd.apache.org/docs/1.3/misc/FAQ-F.html#nph-scripts
有任何想法吗?