os:windows专业版
我正在尝试使用psutil获取进程列表及其cpu使用情况,我以管理员身份运行脚本,遇到进程DymoPnpService.exe时失败,可能是什么问题?
import psutil
def process():
plist = psutil.get_process_list()
plist = sorted(plist, key=lambda i: i.name)
for i in plist:
print i.name, i.get_cpu_percent()
def main():
process()
main()
Run Code Online (Sandbox Code Playgroud)
AcroRd32.exe 0.0 AcroRd32.exe 0.0 DymoPnpService.exe
Traceback (most recent call last):
File "C:\Users\krisdigitx\Documents\windowsutil.py", line 13, in <module>
main()
File "C:\Users\krisdigitx\Documents\windowsutil.py", line 10, in main
process()
File "C:\Users\krisdigitx\Documents\windowsutil.py", line 7, in process
print i.name, i.get_cpu_percent()
File "C:\Python27\lib\site-packages\psutil\__init__.py", line 330, in get_cpu_percent
pt1 = self._platform_impl.get_cpu_times()
File "C:\Python27\lib\site-packages\psutil\_psmswindows.py", line 125, in wrapper
raise AccessDenied(self.pid, self._process_name)
AccessDenied: (pid=1832, name='DymoPnpService.exe') …Run Code Online (Sandbox Code Playgroud) 我有一个程序,它给出了一个environement变量
TIME=1328189073
CLIENT[if-modified-since]=Thu, 02 Feb 2012 12:09:40 GMT
HTTP_FILE=/news/rss.xml?edition=uk
HTTP_PORT=80
HTTP_HOST=feeds.bbci.co.uk
HTTP_PROTO=http
CLIENT[host]=feeds.bbci.co.uk
CLIENTID=10
CLIENT[user-agent]=Safari
PWD=/
VERSION=SR.4.2.2.MR.20110523
CLIENT[accept]=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
SHLVL=1
CLIENT[accept-language]=en-gb,en;q=0.5
INTERFACE=192.168.221.196
CLIENT[cache-control]=max-age=0
CLIENT[accept-encoding]=gzip, deflate
HTTP_METHOD=GET
CLIENT[user-agent]
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试从bash脚本访问此变量之一时,它没有给出任何结果
echo ${CLIENT[user-agent]} >> ${LOG}
Run Code Online (Sandbox Code Playgroud)
但这很有效
echo ${TIME} ${CLIENTID} ${USERNAME} ${IP} ${HTTP_METHOD} ${HTTP_PROTO} ${HTTP_HOST} ${HTTP_PORT} ${HTTP_FILE} ${SIZE} >> ${LOG}
Run Code Online (Sandbox Code Playgroud)
知道用户代理无法显示的原因吗?
[root@proxy-001 scripts]# python
Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> from MySQLdb import cursors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 16, in <module>
insert_values= re.compile(restr)
AttributeError: 'module' object has no attribute 'compile'
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
同样的错误:
[root@proxy-001 scripts]# python
Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on …Run Code Online (Sandbox Code Playgroud) 我rlm_python在半径中使用模块,它option82以十六进制或二进制格式从coovachilli 获取DHCP位置.
将其作为字符串捕获显示为此值\001\027\002\025\001+\001\024,但查看python显示的值被截断,因为option82包含suboptions 编码,TLVs-type,length,values其中字段以type开头0x01(circuit ID, per RFC 3046),后跟一个字节长度.
知道如何抓住这个并正确解开选项吗?
我一直在使用解压缩字符串struct.unpack,但不是meaningful..as它没有告诉有关包装suboptions的option82领域.
Python 2.4.3 (#1, May 5 2011, 16:39:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from struct import *
>>> unpack('=hhl',"\001\027\002\025\001+\001\024" )
(5889, 5378, 335620865)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
更新:
Coovachilli是用编译的--locationopt82,它发送位置作为属性,像这样...
rad_recv: Accounting-Request packet from host 10.66.53.49 port 53178, id=101, length=342
ChilliSpot-Version …Run Code Online (Sandbox Code Playgroud) 下面是检查代码,当鼠标位于图像上方时,基本上我想要点击图像....
<ul id="product-list">
<li class="product one-col new">
<ul>
<li class="image" title="sample image">
<a href="#product/1d77e790-f74a-3859-97db-c513cbece39c">
<img width="" height="" alt="" src="/content/images/1.jpg"></img>
<span class="new"> … </span>
<span class="hover"></span>
</a>
<p class="retailer"> … </p>
<p class="brand"></p>
</li>
<li class="price"> … </li>
<li class="name" title="sample image"> … </li>
<li class="first-seen"> … </li>
</ul>
</li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
Run Code Online (Sandbox Code Playgroud)
我正在使用python selenium,并尝试了下面的单击span(悬停)链接
browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a > span.hover …Run Code Online (Sandbox Code Playgroud) 我有这段代码,它将 JSON 数据提交到服务器,但是它给出了错误“unhashable type list”
hcatalog_nodes =["idh30-1.srv.acent.net.uk","idh30-2.srv.acent.net.uk","idh30-3.srv.acent.net.uk"]
for node in hcatalog_nodes:
data = json.dumps({[
{
"rolename": "HCatalog",
"hostname": node
}
]})
request = urllib2.Request("https://192.168.0.76:9443/restapi/acent/api/v2/cluster/"+cluster_name+"/services/hbase/roles")
base64string = base64.encodestring('%s:%s' % ("admin", "admin")).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
print "setting up HBase roles on node %s " % (node)
result = urllib2.urlopen(request,data)
print result.read()
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "/home/kshk/PycharmProjects/intelIDH/autoIDH.py", line 287, in <module>
main()
File "/home/kshk/PycharmProjects/intelIDH/autoIDH.py", line 278, in main
add_hcatalogRoles()
File "/home/kshk/PycharmProjects/intelIDH/autoIDH.py", line 147, in add_hcatalogRoles
"hostname": node …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 API 网关与 Lambda 代理集成,
API 服务器接收带有这些参数的请求,即邮政编码和房屋
https://api.domain.com/getAddressproxy?postcode=XX2YZ&house=123
Run Code Online (Sandbox Code Playgroud)
但是,从 API 网关到 Lambda 代理的测试不返回值
https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/Test/getaddressproxy?postcode=XX2YZ&house=123
Run Code Online (Sandbox Code Playgroud)
我认为问题在于 lambda 函数没有将查询字符串参数传递给 API 服务器。
知道如何将查询字符串参数传递给请求对象吗?
代码:
from __future__ import print_function
import json
import urllib2
import ssl
print('Loading function')
target_server = "https://api.domain.com"
def lambda_handler(event, context):
print("Got event\n" + json.dumps(event, indent=2))
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
print("Event here: ")
print(event['path'])
print(event["queryStringParameters"])
req = urllib2.Request(target_server + event['path'])
if event['body']:
req.add_data(event['body'])
# Copy only some headers
copy_headers = ('Accept', 'Content-Type')
for h in copy_headers:
if …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行一个不会显示不同/重复值的SQL查询.
例如,如果使用distinct选项,它将只显示一个唯一的结果,但我想跳过所有检测到的不同值,即不显示不同的值
可能吗?
select col1 d from tb_col where col1 = '123';
col1
------
123
123
(2 rows)
select distinct col1 d from tb_col where col1 = '123';
col1
------
123
(1 row)
Run Code Online (Sandbox Code Playgroud) 我在程序中的一个函数检查哈希文件的md5sum
def check():
print "checking integrity status.."
md5 = subprocess.Popen(["md5sum", "-c", hashfile],shell=False, stdout=subprocess.PIPE)
#fopen = open(basefile, "r")
for f in md5.stdout.readlines():
fc = f.rstrip("\n")
sys.stdout.write("\rChecking..." + fc)
sys.stdout.flush()
Run Code Online (Sandbox Code Playgroud)
现在发生的事情是整个命令首先执行然后使用md5.stdout.readlines从md5进行循环读取,因此它不是动态的,即我执行命令时没有得到输出....有没有办法我可以在命令执行时获得输出...
修复使用glglgl的答案:
def check():
print "checking integrity status.."
md5 = subprocess.Popen(["md5sum", "-c", hashfile],shell=False, stdout=subprocess.PIPE)
#fopen = open(basefile, "r")
fc = "NULL"
i = 0
for f in iter(md5.stdout.readline, ''):
k = fc
fc = f.rstrip("\n")
if "FAILED" in fc:
print fc
i = i + 1
sys.stdout.write("\rChecking... "+ str(i)+ " " + …Run Code Online (Sandbox Code Playgroud) 这个bash脚本可以捕获数据通过STDIN传递时设置的所有环境变量,例如:
echo "Hello" | ./script.sh
Run Code Online (Sandbox Code Playgroud)
script.sh
#!/bin/bash
CAPTURE_FILE=/var/log/capture_data
env >> ${CAPTURE_FILE}
exit 1
Run Code Online (Sandbox Code Playgroud)
它有什么方法我可以在python中做同样的事情?
解决:
这是由此产生的python版本..
#!/usr/bin/env python
import os
import sys
def capture():
log = os.environ
data = open("/tmp/capture.log", "a")
for key in log.keys():
data.write((key))
data.write(" : ")
for n in log[key]:
data.write('%s' % ((n)))
data.write("\n")
data.close()
sys.exit(1)
def main():
capture()
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)