Articles of python

用bash或Python下载,同时保持目录树/结构

我有我需要下载的文件列表,如 www.domain.com/files/archive.zip www.domain.com/img/icon.ico www.domain.com/files/backup/archive.zip www.domain.com/backup/img/icon.ico www.domain.com/archive.zip 这意味着我有这个文件列表中的名称冲突,所以我需要保持目录结构完好,并重新下载这个时候,重新创build它,我还没有发现任何东西甚至在Python urllib类似,我不知道任何Linux工具,可以为此做好。 任何build议?

计算一个tcpdump文件中的stream的数量

我有一个很大的tcpdump文件,我需要根据(源IP +源端口,目标IP +目标端口)对来识别捕获中的stream量数量。 tcpdump /任何其他工具是否提供了直接获取这些数据的方法? /关于如何优化我的分析器执行此操作的任何提示? 任何帮助/线索非常赞赏。 谢谢。

如何解决yum错误:没有名为CElementTree的模块?

我有以下问题与百胜: $ yum There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named cElementTree Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version […]

Linux RDesktoplocking

我有一个我写的脚本来创build从Linux工作站到Windows服务器的RDP连接。 在插入以太网插孔的机器上使用时,一切都非常棒,但在无线工作站上使用时,rdesktop会在几分钟的活动后始终locking并冻结。 唯一的恢复方法是杀死rdesktop进程并重新启动连接。 也许我没有实现所有正确的rdesktop开关,或者我失去了明显的东西? rdesktop -g "$geometry" -xl -z "$server" 我向其他远程桌面客户端开放,只要他们提供可以通过Bash和Python程序控制的CLI界面。

IIS不会让Python脚本设置标题

我正在试图让Python与IIS 7.5工作。 我已经添加了Python的脚本处理程序: Python本身似乎不是问题。 我已经在命令行运行脚本没有问题。 我用来testingPythonfunction的脚本如下: print print 'HTTP/1.0 Status: 200 OK' print 'Content-type: text/html' print print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>' print '<BODY>' print '<H1>This is a header</H1>' print '<p>' #this is a comment print 'See this is just like most other HTML' print '<br>' print '</BODY>' 问题是IIS似乎在执行python脚本之前将HTTP内容types标头设置为text/plain ,因为当我浏览到浏览器中的python脚本时,我得到以下输出: 我做错了什么,我该如何解决这个问题?

无法在谷歌应用程序引擎中使用MySQL – 加载MySQL数据库模块时出错:没有名为_mysql的模块。 我正在使用cloudSQL

我正在使用googleAppEngineLauncher尝试MySQL连接。 它给出了日志 File "/Users/kakshilshah/Desktop/hope/skeduleBackend/django/utils/importlib.py", line 40, in import_module __import__(name) File "/Users/kakshilshah/Desktop/hope/skeduleBackend/django/db/backends/mysql/base.py", line 17, in <module> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) ImproperlyConfigured: Error loading MySQLdb module: No module named _mysql 我已经完成了pip install MySQL-python 甚至像python manage.py dbshell这样的命令也可以工作,并将我连接到cloudsql后端。 我可以访问那里的所有表格。 但是,运行它给出了同样的错误。 我有MySQL 5.6安装。 将以下内容添加到app.yaml – name: MySQLdb version: "latest" 也没有帮助,因为我检查了库目录,并没有mysqldb。 我的设置 – import os DATABASES = […]

Python2作为https客户端与nginx服务器和SSL证书链接错误

我无法让Nginx 1.8与我的证书一起工作,以便我可以使用基于python2的https客户端。 (requests.py,URLLib) 我已经尝试使用Comodo和GlobalTrust通配符证书,并在设置nginx时将它们链接到服务器上,但从python获取此错误。 requests.exceptions.SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 在Nginx上我使用这些指令来设置SSL: ssl_session_cache shared:SSL:20m; ssl_session_timeout 10m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:AES128-GCM-SHA256:HIGH:!MD5:!aNULL:!EDH:!CAMELLIA; ssl_protocols TLSv1.2 TLSv1.1 SSLv3; #ssl_protocols TLSv1.2 TLSv1.1 TLSv1; ssl_prefer_server_ciphers on; ssl_certificate /etc/nginx/alphassl/cert_bundle.crt; ssl_certificate_key /etc/nginx/newkey/key.key; 和我一起在服务器上链接证书 cat server.crt intermediate.crt root.crt > cert_bundle.crt 和Comodo: cat server.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > ssl_bundled.crt 它适用于curl,chrome和python3,但我需要能够从Python 2.7.6使用类似的请求来访问它 import requests requests.get('https://server.com/', verify=True) 我也可以向https://store.ssl2buy.com/发送一个请求,从python2这是我的证书的供应商,所以我相信这是一个服务器,而不是python客户端的问题。 […]

NGINX + uWSGI +烧瓶。 有些请求非常慢

我们正在运行一个相当大的Flask应用程序,发现在随机的时候,我们会得到一个非常缓慢的请求(有时一分钟或更多) 我认为这个问题与延迟加载模块有关,而慢速请求则是当新工作者需要启动或重新加载时。 (我们原来有Apache + mod_wsgi的这个问题,但是决定尝试使用uWSGI,因为它是对工作者的先行工作)。 但即使重装不一致。 通常我可以重新加载,请求有点慢,但不显着。 我知道延迟加载是在Django中的东西,但据我所知文档Flask不这样做,除非它configuration为。 我不知道为什么请求会继续这么慢。 为了增加神秘感,我在EC2后面运行这个负载平衡器(仅仅用一个实例)。 通过负载均衡器连接时,我似乎遇到了比直接连接时更多的问题,但又是随机的。 通过负载平衡器的大多数请求不会超过10ms左右。 这里有各种configuration: nginx的: server { listen 80; server_name dev.mysite.net root /var/www/mysite; location / { include uwsgi_params; uwsgi_pass unix:/var/run/uwsgi/mysite.sock; } } uWSGI(皇帝pipe理) [uwsgi] base = /usr app = my_app.py pythonpath = /usr/lib/python2.7 pythonpath = /usr/lib/python2.7/site-packages pythonpath = /usr/lib/python2.7/dist-packages pythonpath = /var/www/mysite socket = /var/run/uwsgi/%n.sock module […]

vCSA命令行安装程序无法部署,出现错误“无法login到主机…不是VIM服务器”

我正在使用Linux下的vcsa-cli-installer实用程序(CentOS 6)来部署VCSA 6.0(vCenter Server Appliance)。 它与以下失败: # ./vcsa-deploy -v ~/full_conf.json Start vCSA command line installer to deploy vCSA "vcsa.example.com", an embedded node. Please see /tmp/vcsa-cli-installer-70USW3.log for logging information. The SSO password meets the installation requirements. Traceback (most recent call last): File "/build/toolchain/lin64/cx-Freeze-4.3.3/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module> File "install.py", line 160, in <module> File "/build/mts/release/bora-2494545/bora/install/vcsa-installer/vcsaCliInstaller/util.py", line […]

无法连接到局域网上的python服务器

所以我有这个python服务器,它只是返回input的大写句子: from socket import * serverPort = 12000 serverSocket = socket(AF_INET, SOCK_DGRAM) serverSocket.bind(('192.168.1.2', serverPort)) print "The server is ready to receive on port: {}".format(serverPort) while 1: message, clientAddress = serverSocket.recvfrom(2048) print clientAddress, message modifiedMessage = message.upper() serverSocket.sendto(modifiedMessage, clientAddress) 从这个客户端: from socket import * serverName = "192.168.1.3" serverPort = 12000 clientSocket = socket(AF_INET, SOCK_DGRAM) message = […]